按变量筛选选定的列表

时间:2012-11-02 16:58:27

标签: cakephp cakephp-2.0

我在蛋糕PHP 2.我有问题,我需要你的帮助。这是我的控制器的一些代码(来自StudentsController.php),特别是“编辑”功能:

$students = $this -> Student -> find('list', array(
    'order' => 'Student.name ASC'
));
$this -> set('students', $students);

如何按当前学生班级过滤列表,以便列表中包含所有具有相同学生班级的学生?

我需要一些像这样的代码

$students = $this -> Student -> find('list', array(
    'conditions' => array('Student.class_id' => CURRENT-STUDENT'S-CLASS),
    'order' => 'Student.name ASC'
));
$this -> set('students', $students);

1 个答案:

答案 0 :(得分:0)

因此根据您的编辑功能,您的查找应该看起来像这样。

$students = $this -> Student -> find('list', array(
'conditions' => array('Student.class_id' => $this->request->data['Student']['class_id']),
'order' => 'Student.name ASC'

));