Home > php教程 > PHP开发 > body text

Overcoming CakePHP Series 2 Form Data Display

黄舟
Release: 2016-12-19 10:52:01
Original
1121 people have browsed it

Cakephp form data display method steps

First create the database cake_ext, and execute the following sql text:

CREATE TABLE `companies` (
`id` int(11) NOT NULL auto_increment,
`company` varchar(50) NOT NULL,
`PRice` decimal(8,2) NOT NULL,
`change` decimal(8,2) NOT NULL,
`lastudp` date NOT NULL,
PRIMARYKEY(`id`)
)ENGINE=MyISAMAUTO_INCREMENT=8DEFAULTCHARSET =utf8;

-----------------------------
-- Records
---------- --------------------
INSERT INTO `companies` VALUES ('1', '3m Co', '71.72', '0.02', '2008-10- 21');
INSERT INTO `companies` VALUES ('2', 'Alcoa Inc', '29.01', '0.42', '2008-10-20');
INSERT INTO `companies` VALUES ('3', 'AT&T Inc.', '31.61', '-0.48', '2008-10-21');
INSERT INTO `companies` VALUES ('4', 'Boeing Co.', '75.43', '0.53', '2008-10-13');
INSERT INTO `companies` VALUES ('5', 'United Technologies Corporation', '63.26', '0.55', '2008-10-09');
INSERT INTO `companies` VALUES ('6', 'Intel Corporation', '19.88', '0.31', '2008-10-15');
INSERT INTO `companies` VALUES ('7', 'Exxon Mobil Corp', '68.10', '-0.43', '2008-10-17');
Create the project as shown below:

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='Companies';

functionindex()
{
$this->set('companies',$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














< ;td>




Idcompany pricechangelast update

link($company['Company']['company'],"/companies/view/".$company['Company']['id']); ?>

view.thtml:

Company:


Id:


Price:


Change:


< ;p>LastUpdate:


Visit http://localhost/cakephp/companies to run the test program.

The above is the content displayed in the form data of Overcoming CakePHP Series 2. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!