


Set up database and model using CakePHP scaffolding tool_PHP tutorial
CakePHP scaffolding tool is mainly used to set up databases and models. The following introduces the operating principles and methods of this CakePHP scaffolding tool.
We already know that model classes are usually used to interact with the database. In CakePHP, a model class usually corresponds to one table in the database. All database operations on tables are implemented through the corresponding model classes. The correspondence between CakePHP's model and database table does not need to be set. Instead, CakePHP uses some simple naming rules to achieve this effect. In this part, we will learn how to create the model class for the table in the database. CakePHP provides a tool called "Scaffolding" to help us inspect previously created models and database tables. We'll also see how to do this using the "Scaffolding" feature.
Create a model for a table in the database
Before understanding how the model class interacts with the database table, we first need to create a database table. In this next section, we'll first create a database table and then see how to create a model class for this table. Then we will also use the scaffolding function to conduct a quick test on the newly created model and data table.
Hands-on time: Create a database table and corresponding model
1. In the MySQL command prompt, we enter the following database command to create a new database named data-access.
<ol class="dp-sql"><li class="alt"><span><span class="keyword"><strong><font color="#006699">CREATE</font></strong></span><span> </span><span class="keyword"><strong><font color="#006699">DATABASE</font></strong></span><span> `data-access`; </span></span></li></ol>
2. Create a "books" table by executing the following SQL statement:
<ol class="dp-sql"> <li class="alt"><span><span>USE `data-access`; </span></span></li> <li class=""> <span></span><span class="keyword"><strong><font color="#006699">CREATE</font></strong></span><span> </span><span class="keyword"><strong><font color="#006699">TABLE</font></strong></span><span> `books` ( </span> </li> <li class="alt"> <span>`id` </span><span class="keyword"><strong><font color="#006699">int</font></strong></span><span>( 11 ) </span><span class="op"><font color="#808080">NOT</font></span><span> </span><span class="op"><font color="#808080">NULL</font></span><span> AUTO_INCREMENT </span><span class="keyword"><strong><font color="#006699">PRIMARY</font></strong></span><span> </span><span class="keyword"><strong><font color="#006699">KEY</font></strong></span><span> , </span> </li> <li class=""> <span>`isbn` </span><span class="keyword"><strong><font color="#006699">varchar</font></strong></span><span>( 10 ) </span><span class="op"><font color="#808080">NOT</font></span><span> </span><span class="op"><font color="#808080">NULL</font></span><span> , </span> </li> <li class="alt"> <span>`title` </span><span class="keyword"><strong><font color="#006699">varchar</font></strong></span><span>( 127 ) </span><span class="op"><font color="#808080">NOT</font></span><span> </span><span class="op"><font color="#808080">NULL</font></span><span> , </span> </li> <li class=""> <span>`description` text </span><span class="op"><font color="#808080">NOT</font></span><span> </span><span class="op"><font color="#808080">NULL</font></span><span> , </span> </li> <li class="alt"> <span>`author_name` </span><span class="keyword"><strong><font color="#006699">varchar</font></strong></span><span>( 127 ) </span><span class="op"><font color="#808080">NOT</font></span><span> </span><span class="op"><font color="#808080">NULL</font></span><span> </span> </li> <li class=""><span>) </span></li> <li class="alt"><span> </span></li> </ol>
3. Place a new CakePHP folder into the root of your web page directory. Rename the Cake folder to data-access.
4 and enter the /app/config directory under the Cake installation folder. You find a file named database.php.default. Rename this file to database.php. Open it using your favorite editor. Edit the $default array in the file to configure your database. After editing, it should look similar to the following content
<ol class="dp-sql"> <li class="alt"><span><span>var $</span><span class="keyword"><strong><font color="#006699">default</font></strong></span><span> = array( </span></span></li> <li class=""> <span> </span><span class="string"><font color="#0000ff">'driver'</font></span><span> => </span><span class="string"><font color="#0000ff">'mysql'</font></span><span>, </span> </li> <li class="alt"> <span> </span><span class="string"><font color="#0000ff">'persistent'</font></span><span> => </span><span class="keyword"><strong><font color="#006699">false</font></strong></span><span>, </span> </li> <li class=""> <span> </span><span class="string"><font color="#0000ff">'host'</font></span><span> => </span><span class="string"><font color="#0000ff">'localhost'</font></span><span>, </span> </li> <li class="alt"> <span> </span><span class="string"><font color="#0000ff">'port'</font></span><span> => </span><span class="string"><font color="#0000ff">''</font></span><span>, </span> </li> <li class=""> <span> </span><span class="string"><font color="#0000ff">'login'</font></span><span> => </span><span class="string"><font color="#0000ff">'username'</font></span><span>, </span> </li> <li class="alt"> <span> </span><span class="string"><font color="#0000ff">'password'</font></span><span> => </span><span class="string"><font color="#0000ff">'password'</font></span><span>, </span> </li> <li class=""> <span> </span><span class="string"><font color="#0000ff">'database'</font></span><span> => </span><span class="string"><font color="#0000ff">'data-access'</font></span><span>, </span> </li> <li class="alt"> <span> </span><span class="string"><font color="#0000ff">'schema'</font></span><span> => </span><span class="string"><font color="#0000ff">''</font></span><span>, </span> </li> <li class=""> <span> </span><span class="string"><font color="#0000ff">'prefix'</font></span><span> => </span><span class="string"><font color="#0000ff">''</font></span><span>, </span> </li> <li class="alt"> <span> </span><span class="string"><font color="#0000ff">'encoding'</font></span><span> => </span><span class="string"><font color="#0000ff">''</font></span><span> </span> </li> <li class=""><span> ); </span></li> </ol>
5. Now, enter the following address in your browser

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

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.

Cryptocurrency data platforms suitable for beginners include CoinMarketCap and non-small trumpet. 1. CoinMarketCap provides global real-time price, market value, and trading volume rankings for novice and basic analysis needs. 2. The non-small quotation provides a Chinese-friendly interface, suitable for Chinese users to quickly screen low-risk potential projects.

When choosing a digital currency trading platform suitable for beginners, you need to consider security, ease of use, educational resources and cost transparency: 1. Priority is given to platforms that provide cold storage, two-factor verification and asset insurance; 2. Apps with a simple interface and clear operation are more suitable for beginners; 3. The platform should provide learning tools such as tutorials and market analysis; 4. Pay attention to hidden costs such as transaction fees and cash withdrawal fees.

The reliable and easy-to-use virtual currency exchange apps are: 1. Binance, 2. OKX, 3. Gate.io, 4. Coinbase, 5. Kraken, 6. Huobi Global, 7. Bitfinex, 8. KuCoin, 9. Bittrex, 10. Poloniex. These platforms were selected as the best for their transaction volume, user experience and security, and all offer registration, verification, deposit, withdrawal and transaction operations.

The top three top ten free market viewing software in the currency circle are OKX, Binance and gate.io. 1. OKX provides a simple interface and real-time data, supporting a variety of charts and market analysis. 2. Binance has powerful functions, accurate data, and is suitable for all kinds of traders. 3. gate.io is known for its stability and comprehensiveness, and is suitable for long-term and short-term investors.

Recommended apps for the top ten virtual currency viewing platforms: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi, 5. Coinbase, 6. Kraken, 7. Bitfinex, 8. KuCoin, 9. Bybit, 10. Bitstamp, these platforms provide real-time market trends, technical analysis tools and user-friendly interfaces to help investors make effective market analysis and trading decisions.

Domestic user adaptation solutions include compliance channels and localization tools. 1. Compliance channels: Franchise currency exchange through OTC platforms such as Circle Trade, domestically, they need to go through Hong Kong or overseas platforms. 2. Localization tools: Use the currency circle network to obtain Chinese information, and Huobi Global Station provides a meta-universe trading terminal.

The most suitable platforms for trading Meme coins include: 1. Binance, the world's largest, with high liquidity and low handling fees; 2. OkX, an efficient trading engine, supporting a variety of Meme coins; 3. XBIT, decentralized, supporting cross-chain trading; 4. Redim (Solana DEX), low cost, combined with Serum order book; 5. PancakeSwap (BSC DEX), low transaction fees and fast speed; 6. Orca (Solana DEX), user experience optimization; 7. Coinbase, high security, suitable for beginners; 8. Huobi, well-known in Asia, rich trading pairs; 9. DEXRabbit, intelligent
