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:
- <?php
- class companiescontroller extends appcontroller
- {
- var $name = ' Companies ';
- function index ()
- {
- $this->set (' companies ', $this->company- >findall ());
- }
- function view ($id = null)
- {
- $this->company->id = $id;
- $this->set (' Company ', $this->company->read ());
- }
- function Add ()
- {
- if (! Emptyempty($this->data))
- {
- if ($this->company->save ($this->data))
- {
- $this->flash (' Your post has been saved. ' ,'/companies ');
- }
- }
- }
- function edit ($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:
- <?php
- class company extends appmodel
- {
- var $name = ' company ';
- var $validate = array(
- ' company ' => valid_not_empty,
- ' price ' => valid_not_empty,
- ' Change ' => valid_not_empty,
- ' lastupd ' => valid_not_empty
- );
- }
- ?>
Index.thtml:
- <table>
- <tr>
- <th>Id</th>
- <th>company</th>
- <th>price</th>
- <th>change</th>
- <th>last update</th>
- </tr>
- <?php foreach ($companies as $company ):?>
- <tr>
- <td><?php echo $company[' company '] [' id ' ];?></td>
- <td>
- <?php echo $html->link ($company[' company '] [ ' company '], "/companies/view/". $company [' Company '][' id']);?>
- <?php echo $html->link (' Delete ', /companies/delete/{$ company[' company ' [' ID ']} ', NULL, ' Are you sure? ' )?>
- </td>
- <td><?php echo $company[' company '] [' Price '];?></td>
- <td><?php echo $company[' company '] [' Change ' ];?></td>
- <td><?php echo $company[' company '] [' Lastupd '];?></td>
- </tr>
- <?php endforeach;?>
- </table>
- <p>
- <?php echo $html->link (' Add ', "/companies/add" );?>
- </p>
View.thtml:
- echo $company[' company '] [ ' Company ' ]?>
- <p><small>id: <?php echo $company[' company '] [' Id ']?></small></p>
- <p>price: <?php echo $company[' company '] [' Price ']?></p>
- <p>change: <?php echo $company[' company '] [' Change ' ]?></p>
- <p>lastupdate: <?php echo $company[' company '] [ ' lastupd ' ]?></p>
- <br/>
- <p>
- <?php echo $html->link (' edit ', "/companies/edit/" ) . $company[' Company '] [' id']);?>
- </p>
Add.thtml:
- <form method="POST" action="<?php echo $html->url ('/companies/add ')?>" >
- <p>
- Company:
- <?php echo $html->input (' Company/company '), Array(' size ' => ' ))?>
- <?php echo $html->tagerrormsg (' Company/company ', ' Company is required. ' )?>
- </p>
- <p>
- Price:
- <?php echo $html->input (' Company/price ', array (' size ' => ' )?>
- <?php echo $html->tagerrormsg (' Company/company '), ' price is required. ' )?>
- </p>
- <p>
- Change:
- <?php echo $html->input (' Company/change ', array (' size ' => ' )?>
- <?php echo $html->tagerrormsg (' Company/change ', ' change is required. ' )?>
- </p>
- <p>
- Last Update:
- <?php echo $html->input (' company/lastupd ', array (' size ' => ' )?>
- <?php echo $html->tagerrormsg (' company/lastupd '), ' last Update is required. ' )?>
- </p>
- <p>
- <?php echo $html->submit (' Save ')?> <?php Echo $html->link (' return ', "/companies/index");? >
- </p>
- </form>
Edit.thtml:
- <form method="POST" action="<?php echo $html->url ('/companies/edit ')?>" >
- <?php echo $html->hidden (' company/id ');?>
- <p>
- Company:
- <?php echo $html->input (' Company/company ', array (' size ' => ' )?>
- <?php echo $html->tagerrormsg (' Company/company '), ' Company is required. ' )?>
- </p>
- <p>
- Price:
- <?php echo $html->input (' Company/price ', array (' size ' => ' )?>
- <?php echo $html->tagerrormsg (' Company/company ', ' price is required. ' )?>
- </p>
- <p>
- Change:
- <?php echo $html->input (' Company/change ', array (' size ' => ' )?>
- <?php echo $html->tagerrormsg (' Company/change '), ' change is required. ' )?>
- </p>
- <p>
- Last Update:
- <?php echo $html->input (' company/lastupd ', array (' size ' => ' )?>
- <?php echo $html->tagerrormsg (' company/lastupd ', ' last Update is required. ' )?>
- </p>
- <p>
- <?php echo $html->submit (' Save ')?> <?php echo $html ->link (' return ', "/companies/index");?>
- </p>
- </form>
You can test your code with this access http://localhost/cakephp/companies .