攻克CakePHP系列二 表单数据显示

2019-04-10 15:27:54刘景俊
  •     var $test = array('driver' => 'mysql',
  •                             'connect' => 'mysql_connect',                             'host' => 'localhost',
  •                             'login' => 'root',                             'password' => 'root',
  •                             'database' => 'cake_ext',                             'prefix' => '');
  • }

    companies_controller.php:

      <?php 
    1. class CompaniesController extends AppController {
    2.     var $name = 'Companies';     
    3.     function index()     {
    4.         $this->set('companies', $this->Company->findAll());     }
    5.          function view($id = null)
    6.     {         $this->Company->id = $id;
    7.         $this->set('company', $this->Company->read());     }
    8. } ?>

    company.php:

     

      <?php
    1. class Company extends AppModel {
    2.     var $name = 'Company'; }
    3. ?>

    index.thtml:

      <h1>Test companies</h1>
    1. <table> <tr>
    2. <th>Id</th> <th>company</th>
    3. <th>price</th> <th>change</th>
    4. <th>last update</th> </tr>
    5. <?php foreach ($companies as $company): ?> <tr>
    6. <td><?php echo $company['Company']['id']; ?></td> <td>
  • 相关文章 大家在看