dropdpwn にいくつかのオプションを入力しようとしています。入力フォームに名前のタイトルと国のリストを含むドロップダウンを作成しようとしています。
例えば:
「Mr」、「Mrs」、「Miss」が必要なタイトル
私は方法を試しました:
モデル
// 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 )); ?>
エラー Undefined variable: 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 が必要だとは思いませんでしたか?