首页 > 开发 > PHP > 正文

攻克CakePHP系列三 表单数据增删改

2024-05-04 22:11:55
字体:
来源:转载
供稿:网友

这里声明一点,上例中不小心把数据库表中lastupd字段错打成lastudp,本例子予以更正。

除上诉字段数据库与上例一致。

工程仍沿用上例,如下图:

代码依次为:

database.php:与上例一致。

companies_controller.php:

    <?php 
  1. class CompaniesController extends AppController {
  2.     var $name = 'Companies';     
  3.     function index()     {
  4.         $this->set('companies', $this->Company->findAll());     }
  5.          function view($id = null)
  6.     {         $this->Company->id = $id;
  7.         $this->set('company', $this->Company->read());     }
  8.          function add()
  9.     {         if (!emptyempty($this->data))
  10.         {             if ($this->Company->save($this->data))
  11.             {                 $this->flash('Your post has been saved.','/companies');
  12.             }         }
  13.     }     
  14.     function edit($id = null)     {
  15.         if (emptyempty($this->data))         {
  16.             $this->Company->id = $id;             $this->data = $this->Company->read();
  17.         }         else
  18.         {             if ($this->Company->save($this->data['Company']))
  19.             {                 $this->flash('Your post has been updated.','/companies');
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表