Overcome the problems of adding, deleting, and modifying CakePHP series three-form data. 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 previous example. as stated here, the lastupd field in the database table is accidentally marked as lastudp, which is corrected in this example.
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');
- }
- }
- }
-
- Function Delete($ 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
- Foreach($ Companies As $ Company):?>
- Endforeach;?>
Id |
Company |
Price |
Change |
Last update |
Echo $ Company['Company'] ['Id'];?> |
- Echo $ Html-> Link ($ Company['Company'] ['Company'],"/Companies/view /".$ Company['Company'] ['Id']);?>
-
- Echo $ Html-> Link ('Delete',"/Companies/delete/{$ company ['Company'] ['id']}", Null,'Are you sure? ')?>
|
Echo $ Company['Company'] ['Price'];?> |
Echo $ Company['Company'] ['Change'];?> |
Echo $ Company['Company'] ['Lastup'];?> |
- Echo $ Html-> Link ('Add',"/Companies/add");?>
View. thtml:
- Company: Echo $ Company['Company'] ['Company']?>
Id: Echo $ Company['Company'] ['Id']?>
Price: Echo $ Company['Company'] ['Price']?>
Change: Echo $ Company['Company'] ['Change']?>
LastUpdate: Echo $ Company['Company'] ['Lastup']?>
- Echo $ Html-> Link ('Edit',"/Companies/edit /".$ Company['Company'] ['Id']);?>
Add. thtml:
- Add Company
Edit. thtml:
- Edit Company
Access http: // localhost/cakephp/companies to test the code.
Bytes. Except for the appeal field, the database is consistent with the previous example. The project still follows the example above, such...