Conquer the Cake series three form data to change _php skill

Source: Internet
Author: User
Tags vars

Here it is stated that, in the example above, the LASTUPD field in the database table is incorrectly beaten into LASTUDP, and this example is corrected.

In addition to the Appeal field database is consistent with the previous example.

The above example is still used in the works, as follows:

The code, in turn, is:

Database.php: Consistent with the above example.

companies_controller.php:

  1. <?php
  2. class companiescontroller extends appcontroller
  3. {
  4. var $name = ' Companies ';
  5. function index ()
  6. {
  7. $this->set (' companies ', $this->company- >findall ());
  8. }
  9. function view ($id = null)
  10. {
  11. $this->company->id = $id;
  12. $this->set (' Company ', $this->company->read ());
  13. }
  14. function Add ()
  15. {
  16. if (! Emptyempty($this->data))
  17. {
  18. if ($this->company->save ($this->data))
  19. {
  20. $this->flash (' Your post has been saved. ' ,'/companies ');
  21. }
  22. }
  23. }
  24. function edit ($id = null)
  25. {
  26. if (emptyempty($this->data))
  27. {
  28. $this->company->id = $id;
  29. $this->data = $this->company->read ();
  30. }
  31. Else
  32. {
  33. if ($this->company->save ($this->data[' Company '] )
  34. {
  35. $this->flash (' Your post has been updated. ' ,'/companies ');
  36. }
  37. }
  38. }
  39. function Delete($id)
  40. {
  41. $this->company->del ($id);
  42. $this->flash (' The post with ID: '. $id . ' has been deleted. ' , '/companies ');
  43. }
  44. }
  45. ?>

company.php:

  1. <?php
  2. class company extends appmodel
  3. {
  4. var $name = ' company ';
  5. var $validate = array(
  6. ' company ' => valid_not_empty,
  7. ' price ' => valid_not_empty,
  8. ' Change ' => valid_not_empty,
  9. ' lastupd ' => valid_not_empty
  10. );
  11. }
  12. ?>

Index.thtml:

  1. <table>
  2. <tr>
  3. <th>Id</th>
  4. <th>company</th>
  5. <th>price</th>
  6. <th>change</th>
  7. <th>last update</th>
  8. </tr>
  9. <?php foreach ($companies as $company ):?>
  10. <tr>
  11. <td><?php echo $company[' company '] [' id ' ];?></td>
  12. <td>
  13. <?php echo $html->link ($company[' company '] [ ' company '], "/companies/view/". $company [' Company '][' id']);?>
  14. <?php echo $html->link (' Delete ', /companies/delete/{$ company[' company ' [' ID ']} ', NULL, ' Are you sure? ' )?>
  15. </td>
  16. <td><?php echo $company[' company '] [' Price '];?></td>
  17. <td><?php echo $company[' company '] [' Change ' ];?></td>
  18. <td><?php echo $company[' company '] [' Lastupd '];?></td>
  19. </tr>
  20. <?php endforeach;?>
  21. </table>
  22. <p>
  23. <?php echo $html->link (' Add ', "/companies/add" );?>
  24. </p>

View.thtml:

  1. echo $company[' company '] [ ' Company ' ]?>
  2. <p><small>id: <?php echo $company[' company '] [' Id ']?></small></p>
  3. <p>price: <?php echo $company[' company '] [' Price ']?></p>
  4. <p>change: <?php echo $company[' company '] [' Change ' ]?></p>
  5. <p>lastupdate: <?php echo $company[' company '] [ ' lastupd ' ]?></p>
  6. <br/>
  7. <p>
  8. <?php echo $html->link (' edit ', "/companies/edit/" ) . $company[' Company '] [' id']);?>
  9. </p>

Add.thtml:

  1. <form method="POST" action="<?php echo $html->url ('/companies/add ')?>" >
  2. <p>
  3. Company:
  4. <?php echo $html->input (' Company/company '), Array(' size ' => ' ))?>
  5. <?php echo $html->tagerrormsg (' Company/company ', ' Company is required. ' )?>
  6. </p>
  7. <p>
  8. Price:
  9. <?php echo $html->input (' Company/price ', array (' size ' => ' )?>
  10. <?php echo $html->tagerrormsg (' Company/company '), ' price is required. ' )?>
  11. </p>
  12. <p>
  13. Change:
  14. <?php echo $html->input (' Company/change ', array (' size ' => ' )?>
  15. <?php echo $html->tagerrormsg (' Company/change ', ' change is required. ' )?>
  16. </p>
  17. <p>
  18. Last Update:
  19. <?php echo $html->input (' company/lastupd ', array (' size ' => ' )?>
  20. <?php echo $html->tagerrormsg (' company/lastupd '), ' last Update is required. ' )?>
  21. </p>
  22. <p>
  23. <?php echo $html->submit (' Save ')?> <?php Echo $html->link (' return ', "/companies/index");? >
  24. </p>
  25. </form>

Edit.thtml:

  1. <form method="POST" action="<?php echo $html->url ('/companies/edit ')?>" >
  2. <?php echo $html->hidden (' company/id ');?>
  3. <p>
  4. Company:
  5. <?php echo $html->input (' Company/company ', array (' size ' => ' )?>
  6. <?php echo $html->tagerrormsg (' Company/company '), ' Company is required. ' )?>
  7. </p>
  8. <p>
  9. Price:
  10. <?php echo $html->input (' Company/price ', array (' size ' => ' )?>
  11. <?php echo $html->tagerrormsg (' Company/company ', ' price is required. ' )?>
  12. </p>
  13. <p>
  14. Change:
  15. <?php echo $html->input (' Company/change ', array (' size ' => ' )?>
  16. <?php echo $html->tagerrormsg (' Company/change '), ' change is required. ' )?>
  17. </p>
  18. <p>
  19. Last Update:
  20. <?php echo $html->input (' company/lastupd ', array (' size ' => ' )?>
  21. <?php echo $html->tagerrormsg (' company/lastupd ', ' last Update is required. ' )?>
  22. </p>
  23. <p>
  24. <?php echo $html->submit (' Save ')?> <?php echo $html ->link (' return ', "/companies/index");?>
  25. </p>
  26. </form>

You can test your code with this access http://localhost/cakephp/companies .

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.