下面的程式碼是Cakephp下對表單資料的增加,刪除,修改實作程式碼
這裡聲明一點,上例中不小心把資料庫表中lastupd欄位錯打成lastudp,本範例予以更正。
除上訴字段資料庫與上例一致。
工程仍沿用上例,如下圖:
程式碼依序為:
database.php:與上例一致。 I ());
}functionview($id= null){
$this->Company->id =$id;
$this->set('company',$this->Company->read( ));
}
functionadd()
{
if(!emptyempty($this->data))
{
{
$ this->Flash('Your post has been saved.','/companies');
}
}
}
functionedit($id= null)
{
if(emptyempty($-this> {
$this->Company->id =$id;
$this->data =$this->Company->read();
}
else
{
if($this->Company->save( $this->data['Company']))
{
}
}
}
functiondelete($id)
}
}
functiondelete($id)
}
}
functiondelete($id)
}
}
functiondelete($id)
}
}
functiondelete($id) {
$this->Company->del($id);
$this->flash('The post with id: '.$id.' has been deleted.','/companies');
}
?>
company.php:
classCompanyextendsAppModel
{
var$name='Company';
var$validate=array(
'company';
var$validate=array(
'company';
'company';
_Tvar$validate=array(
'company';
_NOTn_EM>PNOn_Fx
'change'=> VALID_NOT_EMPTY,
'lastupd'=> VALID_NOT_EMPTY
);
}
?>
index.thtml:
index.thtml:
link('add',"/companies/add"); ?>
Id:
🎜Price:
🎜Change:
🎜LastUpdate:
🎜🎜link('edit',"/companies/edit/ ".$company['Company']['id']); ?>🎜
🎜add.thtml:🎜