开发者

Convert a text box to dropdown box from Add view

Can you help me figure this out please? I have 4 form elements on my add view (app\views\tickets\add.ctp) but the 'status' input is on a text box. I want that to be converted to drop down box populated with data from a field in a table called Status. How do I go about doing it?

echo $this->Form->input('problemno');
echo $this->Form->input('status');
echo $this->Form-&开发者_如何学运维gt;input('description');
echo $this->Form->input('user_id');

Thanks,

Lyman


If you want to force the type of input field, do not use the input() method, but use the method for the type you want.

To get a drop down list, you can use the select() method:

$options = array('status1' => 'status1', 'status2' => 'status2', ...);
$this->Form->select('status', $options);

See http://book.cakephp.org/view/1430/select


If the model associated with your 'Status' table is related to you current model ('Ticket', presumably) with a hasMany,hasOne, or belongsTo (...as long as your 'Status' model shows up when you debug $this->Ticket->read(null, <some_ticket_id>)) you can do

echo $this->Form->input('StatusModel.field')

and cake will automagic that field to be whatever it needs to be.

You will have to search around for how to make cakePHP give you a dropdown selection based on database field.


This is not exactly a correct way. It might be good, or you might find changing it later on to be a problem. But if you just want to create a dropdown with some options, here you go:

echo $this->Form->input('status', array('options'=>array('status1'=>'status1','status2'=>'status2','status3'=>'status3')));

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜