jjzjj

beforeFind

全部标签

php - 修改 beforeFind 回调中所需的 Containable 字段?

在我的CakePHP1.2.5应用程序中,我有一个属于User模型的Profile模型。User模型有一个username字段,当对Profile模型执行find()时,我希望始终自动检索User.username也是。我认为修改我的Profile模型的beforeFind()方法以自动包含所需字段是有意义的。这是我尝试做的:publicfunctionbeforeFind($queryData){//determineiftheusernamedatawasalreadyrequestedtobeincludedinthereturndatavia'User.username'or'

php - cakephp 2.x beforeFind关联模型

如何将beforeFind()条件传播到相关模型中?以School、Course和Term为例(应该是Class,但这个词在php中是保留的),这是Course模型上使用的代码:/***beforeFindmethod**Filtersbytheschool(basedontheurl)*@paramarray$queryThefindquery*@returnarray$queryThequerywiththeaddedcondition*/publicfunctionbeforeFind($query=array()){parent::beforeFind($query);$que

php - beforeFind() 添加条件

我正在尝试根据客户端条件过滤我的应用程序中返回的所有内容。这是在我的AppModel中:publicfunctionbeforeFind($queryData){parent::beforeFind();$queryData['conditions']=array('client_id'=>2);$this->log($queryData);}虽然它不会过滤返回的内容,但条件信息会显示在日志中。我做错了什么? 最佳答案 使用beforeFind()如果您希望查找使用它,您应该返回您已修改的$queryData数组。这是您当前的问题。

activerecord - Yii ActiveRecord 和缓存中的 beforeFind()

在一些模型类中我想实现缓存。我想这样做:UsersModel::model()->findByAttributes([...])在那个类中,我想覆盖方法beforeFind()以首先将请求发送到缓存服务器,但似乎该方法不采用任何额外参数,也没有具有属性的对象。在顶级代码中加入额外的条件/检查,例如:$response=Yii::app()->cache->get('userUserLogin');if(empty($response)==true){//fetchdatafromdbandsettocache$userModel=UsersModel::model->findByAtt