Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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 按变量筛选所选列表_Cakephp_Cakephp 2.0 - Fatal编程技术网

Cakephp 按变量筛选所选列表

Cakephp 按变量筛选所选列表,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,我在cakePHP 2上。我有个问题,我需要你的帮助。以下是我的控制器(来自studentscoontroller.php)的一些代码,特别是“编辑”函数: $students = $this -> Student -> find('list', array( 'order' => 'Student.name ASC' )); $this -> set('students', $students); 如何按当前学生的班级筛选该列表,以便该列表将包含具有相同学生班

我在cakePHP 2上。我有个问题,我需要你的帮助。以下是我的控制器(来自studentscoontroller.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);

因此,根据您的编辑功能,您的查找应该如下所示

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

)))

你有你正在编辑的学生的id吗?你是如何得到当前学生的类的?嗨,科尔比,我需要用正确的代码替换当前学生的类,但我不知道:(显示你的整个编辑函数
public function edit($id=null){$this->STUDENT->id=$id;if($this->request->is('get')){$this->request->data=$this->STUDENT->read();}else{if($this->Student->save($this->request->data)){$this->Session->setFlash('Student已更新');$this->redirect(数组('action'=>'index'));}else($this->Session->setFlash('cannot updatestudent.');}$Student=$this->Student->find('list',array('order'=>'Student.name ASC'))$this->set('students',$students);}
查找是否在编辑中,或者您是否正在寻找另一个显示类列表的函数。非常感谢:)它很有魅力。但是$this->request->data是如何工作的呢?我是cakephp的新手:(我强烈建议您遵循博客教程。这将澄清您的许多问题感谢博客教程。我希望成为cakePHP方面的专业人士,请您为我提供更多资源:)Cakephp.org是你的大资源,它有几个部分,包括面包房、视频、教程和api。你真的只需要通过做、阅读、跟踪视频和看别人所做的工作来学习。谷歌是你的朋友。非常感谢你,我会跟随你的指导