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.