Conquer CakePHP Series three forms of data additions and deletions _php tutorial

Source: Internet
Author: User
It is stated here that, in the example above, the LASTUPD field in the database table was incorrectly punched into a lastudp, and this case is corrected.

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

The project still follows the example, such as:

The code is in turn:

Database.php: Consistent with the previous example.

companies_controller.php:

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

company.php:

  1. class Company extends Appmodel
  2. {
  3. var $name = ' company ';
  4. var $validate = array(
  5. ' company ' = Valid_not_empty,
  6. ' price ' = Valid_not_empty,
  7. ' change ' = Valid_not_empty,
  8. ' lastupd ' = Valid_not_empty
  9. );
  10. }
  11. ?>

Index.thtml:

  1. Test Companies

  2. foreach ( $companies as $company):?>
  3. Endforeach ;?>
  4. Company Price Change Last
  5. Id update
    !--? PHP echo $company [ ' company ' ] ' ID ' ];.
  6. !--? php echo $html ->link ( $company [ ' company ' [ ' company ' ], . $company [ ' company ' [ ' ID ' ]);?
  7. !--? php echo $html ->link ( , "/companies/delete/{$company [' Company '] [' ID ']} ' , NULL, is you sure? ' )?
  8. Echo $company[' Company '] [' price '];?> Echo $company[' Company '] [' Change '];?> Echo $company[' Company '] [' lastupd '];?>
  9. Echo $html->link (' Add ', ' /companies/add');?>

View.thtml:

  1. Company: echo $company[' company '][' Company ']?>

  2. ID: echo $company[' company '][' id ' ]?>

  3. Price: echo $company["Company"] [' price '] ?>

  4. Change: echo $company[' company '][' Change ']?>

  5. Lastupdate: echo $company[' company '] [ ' lastupd ' ]?>


  6. Echo $html->link (' edit ', ' /companies/edit/'). $company [' Company '] [' id ']);?>

Add.thtml:

    1. ADD Company

Edit.thtml:

    1. Edit Company

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

http://www.bkjia.com/PHPjc/319619.html www.bkjia.com true http://www.bkjia.com/PHPjc/319619.html techarticle It is stated here that, in the example above, the LASTUPD field in the database table was incorrectly punched into a lastudp, and this case is corrected. In addition to the Appeal field database is consistent with the previous example. The project still follows the example of ...

  • Related Article

    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.