Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.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中获取有限的字段_Php_Mysql_Arrays_Cakephp - Fatal编程技术网

在CakePHP中获取有限的字段

在CakePHP中获取有限的字段,php,mysql,arrays,cakephp,Php,Mysql,Arrays,Cakephp,在cakephp中获取有限字段时遇到问题 以下是查找查询: $payment = $this -> Payment -> find('first', array('recursive' => 2)); 调试时,我得到以下输出 [Pricing] => Array ( [id] => 5 [plan_id] => 1 [price] => 150 [Plan] => Array

在cakephp中获取有限字段时遇到问题

以下是查找查询:

$payment = $this -> Payment -> find('first', array('recursive' => 2));
调试时,我得到以下输出

[Pricing] => Array
    (
        [id] => 5
        [plan_id] => 1
        [price] => 150
        [Plan] => Array
            (
                [id] => 1
                [course] => One
                [course_name] => OnePlus
                [description] => Lorem Ipsum is simply dummy text
                [discount] => 0

            )

    )
但是从
计划
数组中,我只需要获得
课程名称
。所以我试着:

$payment = $this -> Payment -> find('first', array('recursive' => 2, 
                              'fields' => array(
                                          'Pricing.Plan.course_name'
                                          )
                               ));
但我发现错误:
列未找到:1054未知列“字段列表”中的“Pricing.Plan.course\u name”

请帮助我从
计划
数组中仅获取
库名
字段。

尝试:

 $payment = $this -> Payment -> find('first', array('recursive' => 2, 
                          'fields' => array(
                                      'Plan.course_name'
                                      )
                           ));
试试这个

$payment = $this->Payment->find('first', array('recursive' => 2, 
                          'fields' => array(
                                      'Pricing.*','Plan.course_name'
                                      )
                           ));

在2.x中,尽可能避免递归。相反,使用“包含”。