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

5年以前  |  阅读数:936 次  |  编程语言:PHP 

首先建立数据库cake_ext,并执行如下sql文:

  1. CREATE TABLE companies (
  2. id int(11) NOT NULL auto_increment,
  3. company varchar(50) NOT NULL,
  4. price decimal(8,2) NOT NULL,
  5. change decimal(8,2) NOT NULL,
  6. lastudp date NOT NULL,
  7. PRIMARY KEY (id)
  8. ) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
    1. -- ----------------------------
  9. -- Records
  10. -- ----------------------------
  11. INSERT INTO companies VALUES ('1', '3m Co', '71.72', '0.02', '2008-10-21');
  12. INSERT INTO companies VALUES ('2', 'Alcoa Inc', '29.01', '0.42', '2008-10-20');
  13. INSERT INTO companies VALUES ('3', 'AT&T; Inc.', '31.61', '-0.48', '2008-10-21');
  14. INSERT INTO companies VALUES ('4', 'Boeing Co.', '75.43', '0.53', '2008-10-13');
  15. INSERT INTO companies VALUES ('5', 'United Technologies Corporation', '63.26', '0.55', '2008-10-09');
  16. INSERT INTO companies VALUES ('6', 'Intel Corporation', '19.88', '0.31', '2008-10-15');
  17. INSERT INTO companies VALUES ('7', 'Exxon Mobil Corp', '68.10', '-0.43', '2008-10-17');

如下图所示建立工程:

数据库配置文件如下:

  1. class DATABASE_CONFIG
  2. {
  3. var $default = array('driver' => 'mysql',
  4. 'connect' => 'mysql_connect',
  5. 'host' => 'localhost',
  6. 'login' => 'root',
  7. 'password' => 'root',
  8. 'database' => 'cake_ext',
  9. 'prefix' => '');
    1. **var** $test = **array**('driver' => 'mysql',
  10. 'connect' => 'mysql_connect',
  11. 'host' => 'localhost',
  12. 'login' => 'root',
  13. 'password' => 'root',
  14. 'database' => 'cake_ext',
  15. 'prefix' => '');
  16. }

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. }
  15. ?>

company.php:

  1. <?php
  2. class Company extends AppModel
  3. {
  4. var $name = 'Company';
  5. }
  6. ?>
 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例