我是新蛋糕php.I必须在数据库中输入多个城市ID,使用逗号分隔符,如10,11,12,其中10,11,12是城市ID
当我使用此代码时
**<?php
echo $form->input('city_id', array('options' => $city, 'class'=>'input_box2',
'empty' => 'Please select a city'), null, array('id' => 'city_id', 'label' => 'City'
));**
我可以一次插入一个城市ID,但我需要使用逗号分隔符插入多个城市ID。 我正在使用以下代码,但它不起作用。请帮助
**<?php
echo $form->input('city_id', array('options' => $city, 'type'=>'select','multiple'
=> 'true', 'empty' => 'Please select city'), null, array('id' => 'city_id', 'label' => 'City'));**
答案 0 :(得分:1)
您需要修改控制器中的POST数据:
CakePHP 2.x中的
$city_ids = Set::extract('/YourModel/city_id', $this->request->data);
$this->request->data['YourModel']['city_id'] = implode(",", $city_ids);
CakePHP 1.x中的
$city_ids = Set::extract('/YourModel/city_id', $this->data);
$this->data['YourModel']['city_id'] = implode(",", $city_ids);