2012-11-02 65 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