Overcome the problems of adding, deleting, and modifying CakePHP series three-form data

Source: Internet
Author: User
The code below addresses how to add, delete, and modify CakePHP three-form data and how to add, delete, and modify the CakePHP three-form data. the code below shows how to add, delete, and modify the form data in CakePHP, in the above example, the lastupd field in the database table is accidentally converted into lastudp. In this example, the lastupd field is corrected. Except for the appeal field, the database is consistent with the previous example. Project "> <LINKhref =" http :/

The following code adds, deletes, and modifies form data in CakePHP.

Here we declare that, in the previous example, the lastupd field in the database table is mistakenly typed into lastudp, and this example is corrected.

Except for the appeal field, the database is consistent with the previous example.

The project still follows the example above, for example:

 

The code is as follows:

Database. php: same as the previous example.

Companies_controller.php:

ClassCompaniesControllerextendsAppController
{
Var $ name = 'companys ';

Functionindex ()
{
$ This-> set ('companys', $ this-> Company-> findAll ());
}

Functionview ($ id = null)
{
$ This-> Company-> id = $ id;
$ This-> set ('Company', $ this-> company-> read ());
}

Functionadd ()
{
If (! Emptyempty ($ this-> data ))
{
If ($ this-> Company-> save ($ this-> data ))
{
$ This-> flash ('Your post has been saved. ','/companies ');
}
}
}

Functionedit ($ id = null)
{
If (emptyempty ($ this-> data ))
{
$ This-> Company-> id = $ id;
$ This-> data = $ this-> Company-> read ();
}
Else
{
If ($ this-> Company-> save ($ this-> data ['Company'])
{
$ This-> flash ('Your post has been updated. ','/companies ');
}
}
}

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' => VALID_NOT_EMPTY,
'Price' => VALID_NOT_EMPTY,
'Change' => VALID_NOT_EMPTY,
'Lastup' => VALID_NOT_EMPTY
);
}
?>
Index. thtml:

Test companies


















Id Company Price Change Last update

Link ($ company ['Company'] ['Company'], "/companies/view/". $ Company ['Company'] ['id']);?>

Link ('delete', "/companies/Delete/{$ company ['Company'] ['id']}", null, 'Are you sure? ')?>



Link ('Add', "/companies/add");?>


View. thtml:

Company:

Id:


Price:


Change:


LastUpdate:





Link ('edit', "/companies/edit/". $ company ['Company'] ['id']);?>


Add. thtml:

Add Company

Edit. thtml:

Edit Company

Access http: // localhost/cakephp/companies to test the code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.