我正在尝试使用一些选项填充 dropdpwn。我正在尝试为我的输入表单提供一个包含名称标题和国家/地区列表的下拉列表。
例如:
我需要的头衔“先生”、“夫人”、“小姐”
我尝试了以下方法:
模型
// Built a list of search options (unless you have this list somewhere else)
public function __construct($id = false, $table = null, $ds = null) {
$this->titles = array(
0 => __('Mr', true),
1 => __('Mrs', true),
2 => __('Miss', true));
parent::__construct($id, $table, $ds);
}
控制器
public function add() {
if ($this->request->is('post')) {
$this->Member->create();
if ($this->Member->save($this->request->data)) {
$this->Session->setFlash(__('The member has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The member could not be saved. Please, try again.'));
}
}
}
看法
<?php echo $this->Form->input('title',array('class' => 'span10', 'options' => $titles )); ?>
我收到错误未定义变量:标题
我也在模型中尝试过
public $validate = array(
'member_no' => array(
'notempty' => array(
'rule' => array('notempty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'title' => array(
'titlesValid' => array(
'rule' => array('multiple', array(
'in' => array('Mr', 'Mrs', 'Miss'),
'min' => 1
)),
我缺少什么以及对于较长的列表(例如国家/地区)的最佳解决方案是什么,它仅在表格上,所以我认为我不需要标题和国家/地区表和链接 ID?