Conquer CakePHP series two-form data display

Source: Internet
Author: User
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

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.