cakephp从combobox中检索值

cakephp从combobox中检索值,cakephp,combobox,Cakephp,Combobox,我使用以下命令使用数组中的值填充组合框: 查看代码: echo $this->form->input('Price', array('type'=>'select','options'=>$price)); $price=$_GET['Price']; echo $price; 但是,当我选择一个值并单击submit并使用get在视图中检索该值时 查看代码: echo $this->form->input('Price', array('type'=&g

我使用以下命令使用数组中的值填充组合框:

查看代码:

echo $this->form->input('Price', array('type'=>'select','options'=>$price)); 
$price=$_GET['Price'];
echo $price;
但是,当我选择一个值并单击submit并使用get在视图中检索该值时

查看代码:

echo $this->form->input('Price', array('type'=>'select','options'=>$price)); 
$price=$_GET['Price'];
echo $price;
这只给我选择的索引。如何检索与索引关联的值?

如果该行:

echo $this->form->input('Price', array('type'=>'select','options'=>$price)); 
实际上,在你的控制器中,你正在做一些根本错误的事情

这也不对:

$price=$_GET['Price'];
echo $price;
另外,声明一个根本不用的变量有什么意义

echo $_GET['Price'];
同样,这也不是一个好主意,所有的输出都应该通过Cakes函数传递,这是html htmlspecialchars()的快捷方式,但它比htmlspecialchars()做得多一点

你没有跟上。这是正确的做法:

// controller
$this->set('prices', $this->Model->getPrices());

// view
echo $this->form->input('price', array('type'=>'select','options'=> $prices)); 

// Controller
// When you submitted the form you can get the data in the controller in the request object
debug($this->request->data['Model']['price']);

真的。这里有太多的错误,我基本上要为你写一个完整的教程。博客教程将教你一些基本知识。

让我们假设price数组具有给定的结构:

array('1'=>'1000','2'=>'2000', etc etc);
并且视图已在下面的行中显示

echo $this->form->input('Price', array('type'=>'select','options'=>$price));
很明显,您将在
$\u get['Price']中获得唯一的索引

现在,如果您想要
$中的值,请获取['Price']然后更改价格数组

它应该是
数组('1000'=>'1000','2000'=>'2000'等)ie值对


现在,
$\u获得['Price']将为您带来价值

嘿,对不起,我弄错了…这行出现在我的视图中,而不是控制器中。我将它传递给另一个视图。我以后需要使用价格的值。表单助手生成了一个数据结构[Model][field],所以只需执行调试($this->request->data),正如我在接收表单的控制器方法中所写的那样,您将看到它的样子。然而,我建议你做博客教程,它涵盖了所有这些事情。