Cake と mysql は初めてで、単純なジョブ追跡アプリを作成しようとしています。各ジョブのステータスのリストを含むドロップダウン ボックスが必要です。ユーザーがボックス内のアクティブなアイテムを変更すると、これをデータベースに保存したいと思います。
これを処理する方法についてのヘルプは非常に高く評価されます。以下は私がこれまでに試したことです:
データベーステーブルの列挙型から取得したオプションを使用して、ビューに一連のフォームを作成する方法:
<?php $id = count($jobs)-1; ?>
<?php for ($job = count($jobs)-1; $job >= 0; --$job): ?>
<tr>
<td>
<?php echo $this->Form->input('status'.(string)$id, array('type'=>'select', 'class' => 'statusSelect','label'=>'', 'options'=>$states, 'default'=>$jobs[$job]['Job']['Status'])); ?>
</td>
jquery スクリプトを使用して、ドロップダウンごとに on change リスナーを設定し、コントローラーでアクションを呼び出しています。
$(".statusSelect").change(function(){
//Grab job number from the id of select box
var jobNo = parseInt($(this).attr('id').substring(6));
var value = $(this).val();
$.ajax({
type:"POST",
url:'http://localhost/projectManager/jobs',
data:{ 'id': jobNo,
'status':value},
success : function(data) {
alert(jobNo);// this alert works
},
error : function() {
//alert("false");
}
});
});
そして、コントローラーにこの機能があります:
public function changeState($id = null, $status = null) {
//I don't think the id and status are actually
//being placed as arguments to this function
//from my js script
}
ありがとうございました!!!