【php开源代码栏目提醒】:网学会员在php开源代码频道为大家收集整理了book_controller.php提供大家参考,希望对大家有所帮助!
<?php
class BookController extends AppController{
//var $scaffold;
var $name='book';
function index(){
$this->set('books', $this->Book->findAll());
}
function add(){
if (!empty($this->data)) {
if ($this->Book->save($this->data)){
$this->flash('Book has been saved.','/books');
}
}
}
function delete($id){
$this->Book->del($id);
$this->flash('ID: '.$id.' has been deleted.', '/book/index');
}
function edit($id = null){
if (empty($this->data)) {
$this->Book->id = $id;
$this->data = $this->Book->read();
}
else{
if ($this->Book->save($this->data['books'])) {
$this->flash('This book has been updated.','/book/index');
}
}
}
}
?>