how do you create a select with both value and the label the same from an array in cakephp?

巧了我就是萌 提交于 2019-12-05 12:15:10

You can add parameters to the find 'list' method to specify which fields to use for the key and the value.

Example:

    $usernameMap = $this->Article->User->
find('list', array('fields' => array('User.username', 'User.first_name')));

http://book.cakephp.org/view/1022/find-list

array in the controller

$tasktemplateResults = $this->Tasktemplate->find('list', array('fields' => array('Tasktemplate.name')));

and in view

echo $this->Form->select('task', $tasktemplateResults);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!