Cakephp:如何将视图下拉列表中的值传递给控制器索引查询

Cakephp:如何将视图下拉列表中的值传递给控制器索引查询,cakephp,Cakephp,我对MVC真的很陌生,我正在尝试用CakePHP做一些非常简单的事情——我想我不理解整个想法 我的观点是这样的: 我想把这个$selected_value变量传递给我的控制器,这样它就会根据所选的值显示数据,这是我的控制器代码: public function index() { require 'SeasonsController.php'; $seasons = new SeasonsController(); $this->set('results', $this->

我对MVC真的很陌生,我正在尝试用CakePHP做一些非常简单的事情——我想我不理解整个想法

我的观点是这样的:

我想把这个$selected_value变量传递给我的控制器,这样它就会根据所选的值显示数据,这是我的控制器代码:

public function index() 
{
require 'SeasonsController.php';
$seasons = new SeasonsController();
    $this->set('results', $this->result->find('all', array('conditions' => array('Result.season' => $selected_value))));

}

但这不起作用-我一直得到未定义的变量:selected_value error。我做错了什么?这一定很愚蠢。

索引函数通常不会使用所选值。您通常会使用所选值来查看/编辑记录

在索引函数中,您通常会从表中检索记录列表。索引视图将显示列表

通常在编辑函数和视图中使用下拉列表来更新单个记录中的字段

使用bake创建简单的CRUD(create-Read-Update-Delete)函数并查看然后更新它们以满足您的需求是很好的

public function index() 
{
require 'SeasonsController.php';
$seasons = new SeasonsController();
    $this->set('results', $this->result->find('all', array('conditions' => array('Result.season' => $selected_value))));

}