====== jQueryで非同期処理(DB更新) ======
===== テーブル作成 =====
CREATE TABLE IF NOT EXISTS `tasks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
);
===== index.ctp =====
script('jquery-1.3.2.min', array('inline' => false));
echo $html->script('jquery-ui-1.7.3.custom.min', array('inline' => false));
?>
Tasks
create('Task', array('default'=>false));
echo $form->input('title');
echo $form->submit('Add');
echo $form->end();
?>
===== ajax_add.ctp =====
===== ajax.ctp =====
===== tasks_controller.php =====
set('tasks', $this->Task->find('all'));
}
function ajax_add() {
$this->layout = "ajax";
if($this->RequestHandler->isAjax()) {
$title = $this->params['form']['title'];
$this->Task->id = null;
$this->data['Task']['title'] = $title;
$this->Task->save($this->data);
$this->set('t', $title);
}
}
}