Master CakePHP Series 2 form data display, read and conquer CakePHP Series 2 form data display, CakePHP form data display method step first create database cake_ext, and execute the following SQL: CREATETABLE 'companys' ('id' int (11) NOTNULLauto_increment, 'Company' v
How to display CakePHP form data
First, create the database cake_ext and execute the following SQL:
Create table 'companys '(
'Id' int (11) not null auto_increment,
'Company' varchar (50) not null,
'Price' decimal (8, 2) not null,
'Change' decimal (8, 2) not null,
'Lastup' date not null,
PRIMARYKEY ('id ')
) ENGINE = MyISAMAUTO_INCREMENT = 8 DEFAULTCHARSET = utf8;
------------------------------
-- Records
------------------------------
Insert into 'companys' VALUES ('1', '3 m co', '71. 72 ', '0. 02', '2017-10-21 ');
Insert into 'companys' VALUES ('2', 'Alcoa Inc', '29. 01', '0. 42', '2017-10-20 ');
Insert into 'companys' VALUES ('3', 'AT & T Inc. ', '31. 61', '-0.48', '2017-10-21 ');
Insert into 'companys' VALUES ('4', 'Boeing Co. ', '75. 43', '0. 53', '2017-10-13 ');
Insert into 'companys' VALUES ('5', 'United Technologies Corporation ', '63. 26', '0. 55', '2017-10-09 ');
Insert into 'companys' VALUES ('6', 'Intel Corporation ', '19. 88', '0. 31', '2017-10-15 ');
Insert into 'companys' VALUES ('7', 'Exxon Mobil Corp ', '68. 10','-100', '2017-10-17 ');
Create a project as shown in:
The database configuration file is as follows:
ClassDATABASE_CONFIG
{
Var $ default = array ('driver '=> 'mysql ',
'Connect '=> 'MySQL _ connect ',
'Host' => 'localhost ',
'Login' => 'root ',
'Password' => 'root ',
'Database' => 'Cake _ ext ',
'Prefix' => '');
Var $ test = array ('driver '=> 'mysql ',
'Connect '=> 'MySQL _ connect ',
'Host' => 'localhost ',
'Login' => 'root ',
'Password' => 'root ',
'Database' => 'Cake _ ext ',
'Prefix' => '');
}
Companies_controller.php:
ClassCompaniesControllerextendsAppController
{
Var $ name = 'companys ';
Functionindex ()
{
$ This-> set ('companys', $ this-> Company-> findAll ());
}
Functionview ($ id = null)
{
$ This-> Company-> id = $ id;
$ This-> set ('Company', $ this-> company-> read ());
}
}
?>
Company. php:
ClassCompanyextendsAppModel
{
Var $ name = 'Company ';
}
?>
Index. thtml:
Test companies
Id |
Company |
Price |
Change |
Last update |
|
Link ($ company ['Company'] ['Company'], "/companies/view/". $ Company ['Company'] ['id']);?>
|
|
|
|
View. thtml:
Company:
Id:
Price:
Change:
LastUpdate:
Access http: // localhost/cakephp/companies to run the test program.
This code reference from the official example: http://book.cakephp.org/view/326/The-Cake-Blog-Tutorial