Use the CakePHP scaffold tool to set the database and model _ PHP Tutorial

Source: Internet
Author: User
Use the CakePHP scaffold tool to set databases and models. The CakePHP scaffold tool is mainly used to set databases and models. The following describes how to operate the CakePHP scaffold tool. We already know that model classes are usually used as CakePHP scaffolding tools to set databases and models. The following describes how to operate the CakePHP scaffold tool.

We already know that model classes are usually used to interact with databases. In CakePHP, a model class usually corresponds to Mo tables in the database. All database operations on the table are performed through the corresponding model class. You do not need to set the correspondence between CakePHP models and database tables. On the contrary, CakePHP uses some simple naming rules to achieve this effect. in this section, we will learn how to create an existing model class for tables in the database. CakePHP provides a tool named "scaffolding" to help us check previously created models and database tables. We will also learn how to use the scaffolding function to complete this task.

Create a model for a table in the database

Before learning how a model class interacts with a database table, we must first create a database table. In this section, we will first create a database table and then learn how to create a model class for this table. Then we will use the scaffolding function to quickly test the newly created model and data table.

Start time: create a database table and corresponding model

1. in the MySQL command prompt line, enter the following database command to create a new database named data-access.

 
 
  1. CREATE DATABASE `data-access`;

2. execute the following SQL statement to create a "books" table:

 
 
  1. USE `data-access`;
  2. CREATE TABLE `books` (
  3. `id` int( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  4. `isbn` varchar( 10 ) NOT NULL ,
  5. `title` varchar( 127 ) NOT NULL ,
  6. `description` text NOT NULL ,
  7. `author_name` varchar( 127 ) NOT NULL
  8. )

3. place a new CakePHP folder under the root directory of your webpage. Rename the Cake folder to data-access.

4. go to the/app/config directory in the Cake installation folder. You can find a file named database. php. default. Rename this file to database. php. Open it in your favorite editor. Edit the $ default array in the file to configure your database. After editing, it looks like the following content

 
 
  1. var $default = array(
  2. 'driver' => 'mysql',
  3. 'persistent' => false,
  4. 'host' => 'localhost',
  5. 'port' => '',
  6. 'login' => 'username',
  7. 'password' => 'password',
  8. 'database' => 'data-access',
  9. 'schema' => '',
  10. 'prefix' => '',
  11. 'encoding' => ''
  12. );

5. Now, enter the following address in your browser:

Bytes. The following describes how to operate the CakePHP scaffold tool. We already know that model classes are usually used...

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.