Cakephp 使用模型中的表字段创建标签

Cakephp 使用模型中的表字段创建标签,cakephp,cakephp-1.3,Cakephp,Cakephp 1.3,PHP 分贝 我想创建如下标签: ID | Street | Description ----------------------- 1 | Foo | Street 1 description 2 | Bar | Street 2 description 3 | FooFoo | Street 3 description 比如: 我如何使用Cakephp表单帮助器生成它?谢谢 我不明白你为什么要这样做,但这取决于你想在哪里做。如果您在add操作中,显然您无法从数据库中读取数

PHP

分贝

我想创建如下标签:

ID | Street | Description
-----------------------
1  | Foo    | Street 1 description
2  | Bar    | Street 2 description
3  | FooFoo | Street 3 description
比如:


我如何使用Cakephp表单帮助器生成它?谢谢

我不明白你为什么要这样做,但这取决于你想在哪里做。如果您在add操作中,显然您无法从数据库中读取数据,因为数据库中还没有这样的记录。 如果您在编辑操作中,我假设它已烘焙,您在视图中拥有数据。因此,您可以执行以下操作:

在控制器中,应该有如下内容:

echo $this->Form->input('street', array('empty' => '-- select --', 'label' => 'Street.street - Street.description'));
他认为:

//There should be a variable called $street containing the record data for this to work
//The following sets $street, so it is accessible as $street in the view 
$this->set(compact('street'));
如果有许多记录,$street数组将被索引。

Hello$由于数组索引,如果我有多条街道,street['street']['description']不起作用。
echo $this->Form->input('street', array('empty' => '-- select --', 'label' => 'Street.street - Street.description'));
//There should be a variable called $street containing the record data for this to work
//The following sets $street, so it is accessible as $street in the view 
$this->set(compact('street'));
echo $this->Form->input('street', array('empty' => '-- select --', 'label' => $street['Street']['description']));