2012-11-02 63 views
0

我在cakePHP 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); 
+0

所以你有你正在编辑的学生的编号?你如何获得当前的学生类ID –

+0

嗨科尔比,我需要用正确的代码替换** CURRENT-STUDENT'S-CLASS **,但我不知道:( – gonzo

+0

显示您的整个编辑功能 –

回答

0

一些代码,所以要根据你的编辑功能,您应该找到这个样子。

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

));

+0

非常感谢你:) 它正在发挥魅力。 但$ this-> request-> data如何工作?我是一个新的蛋糕PHP :( – gonzo

+0

我强烈建议你按照博客教程。http://book.cakephp.org/2.0/en/getting-started.html#blog-tutorial这将清除你的许多问题 –

+0

感谢您的博客教程我可以请你给我更多的资源,因为我希望成为一个专业的蛋糕PHP :) – gonzo