Aug 21

Cakephp 学习日志 (二) 不指定

bkkkd , 07:54 , 开发应用 , 评论(0) , 引用(0) , 阅读(39710) , Via 本站原创 | |
本来想写model常用方法的使用,但是发现别人写的比我还要好。所以我就没有写了。
但是要指出部分内容是有误的。
find与findAll的区别不是find返回的是第一条符合条件的数据。
find是findAll,findFirst,findCount实际使用的方法。而这三个方法只是一个简化的后的方法。而find默认是返回findFirst形式的数据。
find的另类用法

$this->{model}->find('all',
                               array(
                                       'conditions' => null,//Where的条件
                                       'fields' => null,//显示的字段
                                       'joins' => array(), //关联的表
                                       'limit' => null,//显示的数据条数
                                       'offset' => null,//移动的条数
                                       'order' => null, //排序的条件
                                       'page' => null, //页数
                                       'group' => null, //Group By的条件
                                       )
                               );


我用bindModel与unbindModel的形式

$reviseModel=array('belongTo'=>array('user'));//定义需要修改那部分的model
$this->{model}->unbindModel($reviseModel);//禁止使用revisedModel中定义的model
$this->{model}->find();//搜索数据
$this->{model}->bindModel($reviseModel);//重新加载之前禁止使用的model


以下是别人写的cakephp的model教程


Section 1 What is a model?
什么是model呢?model就是MVC模式中的M。
Model用来做什么呢?它将领域逻辑从表现层和独立的业务逻辑中剥离出来。


Model通常是数据库的访问介质,而且更明确的指定于某一张表(译注:在rails框架中model扮演着active record的角色,因此同时承担着DAO对象的职责)。默认情况下,model使用的表名为model名字的复数形式,比如'User'这个model 对应的表名为'users'。Model可以包含数据校验规则,关联关系以及针对这张表的业务逻辑。下面展示了User model在cake中的具体定义:

Example User Model, saved in /app/models/user.php  
<?php  
  
//AppModel gives you all of Cake's Model functionality  
  
class User extends AppModel  
{  
     // Its always good practice to include this variable.  
     var $name = 'User';
  
     // This is used for validation, see Chapter 11.
     var $validate = array();
  
     // You can also define associations.
     // See section 6.3 for more information.
  
     var $hasMany = array('Image' =>
                    array('className' => 'Image')  
                    );  
  
    // You can also include your own functions:  
     function makeInactive($uid)  
     {  
         //Put your own logic here...  
     }  
}  
  
?>  

(译注:关于Model应该是贫血型,失学型还是充血型的论战持续至今尚无明显得胜的一方,本文中的这句话:Model将领域逻辑从表现层和独立的业务逻辑中剥离出来 说得还比较清晰的,起码在cake里面他就是这么遵循的)
内文分页: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]
Tags:
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]