私は多くの調査を行い、いくつかの異なる例を適用しようとしましたが、実際には何も機能していないようです.
したがって、顧客、プロジェクト、イベントの 3 つのモデルがあります。顧客には多くのプロジェクトがあり、プロジェクトには多くのイベントがあります。
イベントの作成中に、ユーザーにドロップダウン リストから顧客を選択してもらい、選択した顧客に属するプロジェクトのリストをユーザーに提供する必要があります。私が得た最も近いものは次のとおりです。私は AJAX の経験がないので、ブレーキをかけるのは本当に難しいです。
Porject のコントローラーでのアクション:
public function getbycustomer(){
$customer_id = $this->request->data['Event']['customer_id'];
$projects = $this->Project->find('list', array('conditions'=>array('Project.customer_id' => $customer_id), 'recursive' => -1));
$this->set('projects', $projects);
$this->layout = 'ajax';
}
このアクションのビューは次のとおりです。
<?php foreach ($projects as $key => $value): ?>
<option value="<?php echo $key; ?>"><?php echo $value; ?></option>
<?php endforeach; ?>
イベントを追加するためのビューのスニペットは次のとおりです。
echo $this->Form->input('customer_id');
echo $this->Form->input('project_id');
//form continues and at the end of a page there is the AJAX call
$this->Js->get('#EventCustomerId')->event('change',
$this->Js->request(array(
'controller'=>'projects',
'action'=>'getbycustomer'
), array(
'update'=>'#EventProjectId',
'async' => true,
'method' => 'post',
'dataExpression'=>true,
'data'=> $this->Js->serializeForm(array(
'isForm' => true,
'inline' => true
))
))
);
デバッグの適切な方法さえ知らないので、どんな助けも大歓迎です。より価値のある情報を提供できます。