Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cakephp关于afterFind事件的更多字段un$结果_Php_Cakephp - Fatal编程技术网

Cakephp关于afterFind事件的更多字段un$结果

Cakephp关于afterFind事件的更多字段un$结果,php,cakephp,Php,Cakephp,您好,我正在RealState项目中使用cakephp。我有一个HABTM协会,用于一个属于许多业主的物业,事实上,当我在afterFind中阅读任何物业记录时(这里是代码) $results变量,我只获取其关联所有者的ID和NAME字段,因此我想修改任何其他字段,例如电话或电子邮件,这是不可能的,因为数组中没有此字段。有什么解决办法吗 提前感谢。您确定进行搜索的查找没有“字段”参数吗?(即$this->model->find('first',array('fields'=>'model.ID'

您好,我正在RealState项目中使用cakephp。我有一个HABTM协会,用于一个属于许多业主的物业,事实上,当我在afterFind中阅读任何物业记录时(这里是代码)

$results变量,我只获取其关联所有者的ID和NAME字段,因此我想修改任何其他字段,例如电话或电子邮件,这是不可能的,因为数组中没有此字段。有什么解决办法吗


提前感谢。

您确定进行搜索的查找没有“字段”参数吗?(即$this->model->find('first',array('fields'=>'model.ID','model.Name');)查找查询在哪里?请出示它,以便我能帮助你。嗨@Tanatos,我使用的是这个关联public$hasandbelongtomany=array('Owner'=>array)('className'=>'owner','joinTable'=>'owners\u properties','foreignKey'=>'property\u id','associationForeignKey'=>'contact\u id','unique'=>true',conditions'=>'','fields'=>'','order'=>'',limit'=>'','offset'=>'','finderQuery'=>'',with'=>'OwnersProperties')Hi@Sadikhasan查找查询是由cake启动的默认THA我只执行$this->Property->read(),但因此在afterfind之外,我可以访问所有所有者字段。如果您使用
$this->Model->read()
函数,那么cakephp将返回模型的所有字段
function afterFind(&$model, $results, $primary) { 

   //debug($this->settings[$model->alias]['fields']);
    foreach ($this->settings[$model->alias]['fields'] AS $field) {

        if ($primary) { 
         //   if ($model->alias == 'Owner')
                debug($results);
            foreach ($results AS $key => $value) {             
                if (isset($value[$model->alias][$field])) {
                   $results[$key][$model->alias][$field] = $this->decrypt($value[$model->alias][$field]); 
                } 
            } 
        } else { 
            if (isset($results[$field])) { 
                $results[$field] = $this->decrypt($results[$field]); 
            } 
        } 
    } 

    return $results; 
}