Overcoming CakePHP Series 2 Form Data Display
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
Id | company | price | change | last 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)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

Validator can be created by adding the following two lines in the controller.

CakePHP is a powerful PHP framework that provides developers with many useful tools and features. One of them is pagination, which helps us divide large amounts of data into several pages, making browsing and manipulation easier. By default, CakePHP provides some basic pagination methods, but sometimes you may need to create some custom pagination methods. This article will show you how to create custom pagination in CakePHP. Step 1: Create a custom pagination class First, we need to create a custom pagination class. this

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

CakePHP is an open source PHPMVC framework which is widely used in web application development. CakePHP has many features and tools, including a powerful database query builder for interactive performance databases. This query builder allows you to execute SQL queries using object-oriented syntax without having to write cumbersome SQL statements. This article will introduce how to use the database query builder in CakePHP. Establishing a database connection Before using the database query builder, you first need to create a database connection in Ca

CakePHP is an open source web application framework built on the PHP language that simplifies the development process of web applications. In CakePHP, processing file uploads is a common requirement. Whether it is uploading avatars, pictures or documents, the corresponding functions need to be implemented in the program. This article will introduce how to handle file uploads in CakePHP and some precautions. Processing uploaded files in Controller In CakePHP, uploaded files are usually processed in Cont

In this chapter, we are going to learn the following topics related to routing ?
