Table of Contents
Test companies
Home php教程 php手册 攻克CakePHP系列二 表单数据显示

攻克CakePHP系列二 表单数据显示

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

首先建立数据库cake_ext,并执行如下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');

如下图所示建立工程:

数据库配置文件如下:

  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即可运行测试程序。

 

本代码参考自官方自带例子: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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Xiaomi 15 series full codenames revealed: Dada, Haotian, Xuanyuan Xiaomi 15 series full codenames revealed: Dada, Haotian, Xuanyuan Aug 22, 2024 pm 06:47 PM

The Xiaomi Mi 15 series is expected to be officially released in October, and its full series codenames have been exposed in the foreign media MiCode code base. Among them, the flagship Xiaomi Mi 15 Ultra is codenamed "Xuanyuan" (meaning "Xuanyuan"). This name comes from the Yellow Emperor in Chinese mythology, which symbolizes nobility. Xiaomi 15 is codenamed "Dada", while Xiaomi 15Pro is named "Haotian" (meaning "Haotian"). The internal code name of Xiaomi Mi 15S Pro is "dijun", which alludes to Emperor Jun, the creator god of "The Classic of Mountains and Seas". Xiaomi 15Ultra series covers

70B model generates 1,000 tokens in seconds, code rewriting surpasses GPT-4o, from the Cursor team, a code artifact invested by OpenAI 70B model generates 1,000 tokens in seconds, code rewriting surpasses GPT-4o, from the Cursor team, a code artifact invested by OpenAI Jun 13, 2024 pm 03:47 PM

70B model, 1000 tokens can be generated in seconds, which translates into nearly 4000 characters! The researchers fine-tuned Llama3 and introduced an acceleration algorithm. Compared with the native version, the speed is 13 times faster! Not only is it fast, its performance on code rewriting tasks even surpasses GPT-4o. This achievement comes from anysphere, the team behind the popular AI programming artifact Cursor, and OpenAI also participated in the investment. You must know that on Groq, a well-known fast inference acceleration framework, the inference speed of 70BLlama3 is only more than 300 tokens per second. With the speed of Cursor, it can be said that it achieves near-instant complete code file editing. Some people call it a good guy, if you put Curs

AI startups collectively switched jobs to OpenAI, and the security team regrouped after Ilya left! AI startups collectively switched jobs to OpenAI, and the security team regrouped after Ilya left! Jun 08, 2024 pm 01:00 PM

Last week, amid the internal wave of resignations and external criticism, OpenAI was plagued by internal and external troubles: - The infringement of the widow sister sparked global heated discussions - Employees signing "overlord clauses" were exposed one after another - Netizens listed Ultraman's "seven deadly sins" Rumors refuting: According to leaked information and documents obtained by Vox, OpenAI’s senior leadership, including Altman, was well aware of these equity recovery provisions and signed off on them. In addition, there is a serious and urgent issue facing OpenAI - AI safety. The recent departures of five security-related employees, including two of its most prominent employees, and the dissolution of the "Super Alignment" team have once again put OpenAI's security issues in the spotlight. Fortune magazine reported that OpenA

See all articles