国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Test?companies
Home php教程 php手冊 攻克CakePHP系列二 表單數(shù)據(jù)顯示

攻克CakePHP系列二 表單數(shù)據(jù)顯示

Jun 13, 2016 pm 12:26 PM
cake cakephp cr ext sql two Establish implement data database arts show series form first

首先建立數(shù)據(jù)庫cake_ext,并執(zhí)行如下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;
  9. --?----------------------------
  10. --?Records?
  11. --?----------------------------
  12. INSERT?INTO?`companies`?VALUES?('1',?'3m?Co',?'71.72',?'0.02',?'2008-10-21');
  13. INSERT?INTO?`companies`?VALUES?('2',?'Alcoa?Inc',?'29.01',?'0.42',?'2008-10-20');
  14. INSERT?INTO?`companies`?VALUES?('3',?'AT&T?Inc.',?'31.61',?'-0.48',?'2008-10-21');
  15. INSERT?INTO?`companies`?VALUES?('4',?'Boeing?Co.',?'75.43',?'0.53',?'2008-10-13');
  16. INSERT?INTO?`companies`?VALUES?('5',?'United?Technologies?Corporation',?'63.26',?'0.55',?'2008-10-09');
  17. INSERT?INTO?`companies`?VALUES?('6',?'Intel?Corporation',?'19.88',?'0.31',?'2008-10-15');
  18. INSERT?INTO?`companies`?VALUES?('7',?'Exxon?Mobil?Corp',?'68.10',?'-0.43',?'2008-10-17');

如下圖所示建立工程:

數(shù)據(jù)庫配置文件如下:

  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'?=>?'');
  10. ????var?$test?=?array('driver'?=>?'mysql',
  11. ????????????????????????????'connect'?=>?'mysql_connect',
  12. ????????????????????????????'host'?=>?'localhost',
  13. ????????????????????????????'login'?=>?'root',
  14. ????????????????????????????'password'?=>?'root',
  15. ????????????????????????????'database'?=>?'cake_ext',
  16. ????????????????????????????'prefix'?=>?'');
  17. }

companies_controller.php:

  1. class?CompaniesController?extends?AppController
  2. {
  3. ????var?$name?=?'Companies';
  4. ????
  5. ????function?index()
  6. ????{
  7. ????????$this->set('companies',?$this->Company->findAll());
  8. ????}
  9. ????
  10. ????function?view($id?=?null)
  11. ????{
  12. ????????$this->Company->id?=?$id;
  13. ????????$this->set('company',?$this->Company->read());
  14. ????}
  15. }
  16. ?>

company.php:

?

  1. class?Company?extends?AppModel
  2. {
  3. ????var?$name?=?'Company';
  4. }
  5. ?>

index.thtml:

  1. Test?companies

  2. foreach?($companies?as?$company):??>
  3. endforeach;??>??
  4. Id company price change last?update
    echo?$company['Company']['id'];??>
  5. echo?$html->link($company['Company']['company'],?"/companies/view/".$company['Company']['id']);??>
  6. echo?$company['Company']['price'];??> echo?$company['Company']['change'];??> echo?$company['Company']['lastudp'];??>

view.thtml:

  1. Company:?echo?$company['Company']['company']?>

  2. Id:?echo?$company['Company']['id']?>

  3. Price:?echo?$company['Company']['price']?>

  4. Change:?echo?$company['Company']['change']?>

  5. LastUpdate:?echo?$company['Company']['lastudp']?>

訪問http://localhost/cakephp/companies即可運(yùn)行測試程序。

?

本代碼參考自官方自帶例子:http://book.cakephp.org/view/326/The-Cake-Blog-Tutorial

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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MySQL: A Beginner-Friendly Approach to Data Storage MySQL: A Beginner-Friendly Approach to Data Storage Apr 17, 2025 am 12:21 AM

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

MySQL: Structured Data and Relational Databases MySQL: Structured Data and Relational Databases Apr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

The Purpose of SQL: Interacting with MySQL Databases The Purpose of SQL: Interacting with MySQL Databases Apr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Redis: Understanding Its Architecture and Purpose Redis: Understanding Its Architecture and Purpose Apr 26, 2025 am 12:11 AM

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

MySQL: A Practical Application of SQL MySQL: A Practical Application of SQL May 08, 2025 am 12:12 AM

MySQL is popular because of its excellent performance and ease of use and maintenance. 1. Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2. Insert and query data: operate data through INSERTINTO and SELECT statements. 3. Optimize query: Use indexes and EXPLAIN statements to improve performance.

MongoDB's Future: The State of the Database MongoDB's Future: The State of the Database Apr 25, 2025 am 12:21 AM

MongoDB's future is full of possibilities: 1. The development of cloud-native databases, 2. The fields of artificial intelligence and big data are focused, 3. The improvement of security and compliance. MongoDB continues to advance and make breakthroughs in technological innovation, market position and future development direction.

See all articles