私は登録ページを持っており、この登録ページ内でユーザーはいくつかの関心を入力する必要があります。関心の値はinterest.phpという名前のモデルから呼び出され、すべての値がプルスルーされ、期待どおりに保存されます。
ユーザーモデルとの関係は
var $hasAndBelongsToMany = array(
'Interest' => array(
'className' => 'Interest',
'joinTable' => 'users_interests',
'foreignKey' => 'user_id',
'associationForeignKey' => 'interest_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
Interest.phpに検証ルールを追加すると、チェックボックスの横に必要な小さな星が表示されますが、まったく検証されていません。
<label for="InterestInterestId">Interests</label>
<input type="hidden" value="" name="data[Interest][interest_id]">
<div class="checkbox">
<input id="InterestInterestId8" type="checkbox" value="8" name="data[Interest][interest_id][]">
<label for="InterestInterestId8">Interest 1</label>
</div>
<div class="checkbox">
<input id="InterestInterestId1" type="checkbox" value="1" name="data[Interest][interest_id][]">
<label for="InterestInterestId1">Interest2</label>
</div>
私の見解では、私はこのように複数のチェックボックスを呼び出します
echo $form->input('Interest.interest_id', array('label' => __l('Interests'), 'multiple' => 'checkbox'));
これはinterest.phpの私の検証ルールです
$this->validate = array(
'interest_id' => array(
'rule' => array(
'equalTo',
'1'
) ,
'message' => __l('Please select some interests')
)
);
私はここで何か間違ったことをしているのですか、それとも何かが足りないのですか、助けていただければ幸いです!!!!