Heim  >  Artikel  >  php教程  >  关于thinkphp优化的一点总结

关于thinkphp优化的一点总结

WBOY
WBOYOriginal
2016-06-07 17:23:461250Durchsuche

    前段时间为了写一个博客,特地使用thinkphp框架写了一个博客程序wblog,之后对其作了优化,现在感觉到了thinkphp框架的强大之处。

     

    前期的wblog有好多thinkphp的特性没有用上,走的是开发原生态的php系统的思路。thinkphp是一个基于MVC模式的框架,一般来说业务是放在M(模型)上处理的,C(控制器)只负责组织调用M处理好的功能函数使其返回给V(视图)。可是前期的WBLOG中的C似乎肩负着业务处理和组织调控两项任务,这有违MVC的理念了。如把所有的函数都放在公共控制器CommonAction.class.php上,其余的控制器都继承公共控制器,由于函数太多,所以CommonAction.class.php显得有点雍肿,而模型Model却空闲着,什么也不做。

     

    这次对WBlog作了优化,每个表对应着一个Model,负责处理与之相关的逻辑业务,控制器负责组织调控Model处理好的业务。我在前面的"怎样彻底删除thinkphp3.1案例blog的标签?"写过一个删除标签的方法,当初这个删除主法是放在控制器上的,现在我们把它放在模型上,对比一下。

     

    下面这个删除函数是写在公共控制器CommonAction.class.php上的

     

public function deltag($recordId){         
         
      $condition['recordId'] = $recordId;//获取日记的ID   
               
     $tagged=M('Tagged');   
     $taggedlist= $tagged->where($condition)->select();//这里用select而不用find,因为一篇日记可能有多个标签   
                 
   $taggedids=array();//声明一个数组,用来装think
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn