PHP
echo $this->Form->create('Street');
echo $this->Form->input('street', array('empty' => '-- select --', 'label' => '???'));
DB
ID | Street | Description
-----------------------
1 | Foo | Street 1 description
2 | Bar | Street 2 description
3 | FooFoo | Street 3 description
I want to create label like:
Foo - Street 1 description
Like:
echo $this->Form->input('street', array('empty' => '-- select --', 'label' => 'Street.street - Street.description'));
How I can generate this with Cakephp Form Helper? Thanks!
I don’t understand why you’d like to do this, but it depends on where you want to do it. If you’re in the add action obviously you cannot read from the DB because there is no such record in it yet.
If you’re in the edit action (I assume it has been baked) you have the data in the view. So you can do the following:
In the controller there should be something like:
In the view:
If there are many records, the
$streetarray will be indexed.