如何创建表单选择制作值与db数组中的选项文本相同

时间:2016-06-21 18:03:01

标签: php html cakephp cakephp-1.3

我们说我在控制器中了:

$this->set('locations', $this->Location->find('list', array('fields' => array('state')) )); 

如何通过选项生成表单选择视图:

<select name="data[Location][state]" class="inputbox" id="Location">
<option value="Arizona">Arizona</option>
<option value="California">California</option>
<option value="Hawaii">Hawaii</option>
</select>

因为它正在生成:

<select name="data[Location][state]" class="inputbox" id="Location">
    <option value="1">Arizona</option>
    <option value="2">California</option>
    <option value="3">Hawaii</option>
    </select>

我知道cakephp默认使用主键作为值,并且有一个已回答的问题,但解决方案对我不起作用: how do you create a select with both value and the label the same from an array in cakephp?

在我看来,我有:

<?php echo $form->select('Location.state', $locations); ?>

我的数据库是:locations
id |状态
1 |亚利桑那
2 |加州
3 |夏威夷
等等

3 个答案:

答案 0 :(得分:0)

好吧,解决方案很简单......在我的控制器中,fields数组需要指定值和文本:

$this->set('locations', $this->Location->find('list', array('fields' => array('state','state')) ));

答案 1 :(得分:0)

  

调用list时,您可以分别使用keyField和valueField选项配置用于键和值的字段:

     

http://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#finding-key-value-pairs

 <VirtualHost *:80 *:443>
 ServerAdmin myemail@gmail.com

 ServerName www.mysite.com
 ServerAlias www.mysite.com

 Alias /media/ /var/www/mysite/media/
 Alias /static/ /var/www/mysite/static/

 DocumentRoot /var/www/mysite/media/

 <Directory /var/www/mysite>
     Require all granted
 </Directory>

 WSGIDaemonProcess mysite python-path=/var/www/mysiteenv/lib/python2.7/site-packages:/var/www/mysite
 WSGIProcessGroup mysite
 WSGIScriptAlias / /var/www/mysite/wsgi.py/

 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn

 CustomLog ${APACHE_LOG_DIR}/access.log combined

答案 2 :(得分:0)

static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
{
    return (struct udphdr *)skb_transport_header(skb);
}