在我的cakephp控制器中,当我通过find子句检索数据时,我得到了这个数组
Array
(
[0] => Array
(
[Category] => Array
(
[id] => 1
[Category-name] => Arts
)
[Course] => Array
(
[0] => Array
(
[id] => 1
[category_id] => 1
[degree] => UG
[course-name] => BSc-Maths
)
[1] => Array
(
[id] => 5
[category_id] => 1
[degree] => PG
[course-name] => MSc Math
)
[2] => Array
(
[id] => 6
[category_id] => 1
[degree] => UG
[course-name] => Bsc Stats
)
[3] => Array
(
[id] => 7
[category_id] => 1
[degree] => PG
[course-name] => Msc-Stats
)
)
)
[1] => Array
(
[Category] => Array
(
[id] => 2
[Category-name] => Science and technology
)
[Course] => Array
(
[0] => Array
(
[id] => 2
[category_id] => 2
[degree] => UG
[course-name] => BSc-CS
)
)
)
[2] => Array
(
[Category] => Array
(
[id] => 3
[Category-name] => Commerce
)
[Course] => Array
(
[0] => Array
(
[id] => 3
[category_id] => 3
[degree] => PG
[course-name] => Msc-Finance
)
)
)
[3] => Array
(
[Category] => Array
(
[id] => 4
[Category-name] => Law
)
)
)
我希望以ctp文件的形式显示特定类别的所有课程。至于类别艺术,有4门课程。
我想展示这4门艺术课程。
我可以使用同一数组显示类别。
但是无法使用y ctp文件中的数组作为下拉列表显示使用相同数组的课程。
是否可以访问此课程数据?还是我必须使用其他查询来访问课程?
请帮助我。
先谢谢了。
答案 0 :(得分:0)
我会这样解决:
改进的检索查询,仅输出课程名称。
$cats = $this->Category->find('all',array(
'conditions'=>array('Category.Category-name'=>'Arts')
'recursive'=>1,
'contain'=>array('Course'),
'fields'=>'Course.course-name'))[0]['Course'];
现在$ cats变量应包含一个包含4个条目的数组,可用于下拉选择