


CakePHP 2.x upgrade to 3.0, cakephp2.x upgrade to 3.0_PHP tutorial
CakePHP 2.x upgrade to 3.0, cakephp2.x upgrade to 3.0
CakePHP 2.x => 3.x upgrade instructions
1. Controller layer
1.find('list')
In the original 2.x, this method implements key=>value
by specifying the 'fields' in the option. 3.x uses the 'keyField' and 'keyField' in the option. 'valueField' to replace, the return value needs to be converted using toArray()
2.find('first'), find('count')
3.x has completely abandoned these two parameters, and use find()->first() and find()- >count() to replace
3. When find queries related tables, you must add the 'contain' attribute. Cake 3.x will not associate tables together by default
4.findById
**?No relevant document found?**
The format of findById in 2.x is ($id,array $fields)
3.x may have only one parameter ($ id), you need to filter the data through the select(array $fields) method
5.Component->initialize()
2.x gets the Controller that calls the Component through initialize(Controller $Controller)
3.x changed the parameter of initialize to initialize(array $config) , get
6.SessionComponent
3.x abandoned this Component and used $this->request->session() to replace
2. Model layer
1.Associations
2.x realizes association by defining attributes
3.x needs to call $this->belongsTo, $this->hasMany, $this- in the initialize method in Table >belongsToMany, $this->addAssociations and other methods to achieve
2.Validation
2.x implements data validation by defining the validate attribute
3.x needs to define the validationDefault(Validator $validator) method in Table to implement
3.virtualFields
This attribute was abandoned in 3.x. If you need to use it, you need to add the method
in Entity. For example, you need to define the virtual field full_name in table A
. First, you need to define the virtual field full_name in table A in the Entity. Append protected function _getFullName()
Then add full_name to $_accessible
When using A->find, the value can only be obtained through object->property and cannot be obtained through array
4.field()
**? No relevant document found?**
3.x may have abandoned this method and can be replaced with the get() method
5.ClassRegistry::init()
3.x This method is abandoned and needs to be replaced with TableRegistry::get()
6.Mysql alias setting
2.x only needs to add as in the fields attribute, such as 'fields'=>array('id as table_id')
3.x needs to define an alias Use adding key such as 'fields'=>['table_id'=>'id']
3. View layer
(View layer, moved from the View folder of 2.x to the Template of 3.x)
1.$this->Html->url
In 3.x, use $this->Url->build instead of
4. Bug
1. Associations
When querying hasMany table association, if you need to specify fields, must you add association keys to the fields? ? ?
This upgrade guide will continue to be updated~~~~~~

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

AI Hentai Generator
Generate AI Hentai for free.

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

Several methods for Conda to upgrade the Python version require specific code examples. Overview: Conda is an open source package manager and environment management system for managing Python packages and environments. During development using Python, in order to use a new version of Python, we may need to upgrade from an older Python version. This article will introduce several methods of using Conda to upgrade the Python version and provide specific code examples. Method 1: Use the condainstall command

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

How to upgrade numpy version: Easy-to-follow tutorial, requires concrete code examples Introduction: NumPy is an important Python library used for scientific computing. It provides a powerful multidimensional array object and a series of related functions that can be used to perform efficient numerical operations. As new versions are released, newer features and bug fixes are constantly available to us. This article will describe how to upgrade your installed NumPy library to get the latest features and resolve known issues. Step 1: Check the current NumPy version at the beginning

1. Use the win+x shortcut key to open the menu and select [Command Prompt (Administrator) (A)], as shown below: 2. After entering the command prompt interface, enter the [ipconfig/flushdns] command and press Enter , as shown in the figure below: 3. Then enter the [netshwinsockresetcatalog] command and press Enter, as shown in the figure below: 4. Finally enter the [netshintipreset] command and press Enter, restart the computer and you can access the Internet, as shown in the figure below:

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

In a new technological field, new operating systems always attract much attention. Recently, Honor mobile phones announced that they will be upgraded to Hongmeng OS, a new operating system developed by Huawei. This is undoubtedly good news for many Honor mobile phone users. However, many users may still have doubts about how to upgrade to Hongmeng system. This article will explain in detail how to upgrade Honor mobile phones to Hongmeng system to help users better understand and operate it. First of all, to upgrade an Honor phone to the Hongmeng system, users need to ensure that the phone is connected to the network and has sufficient power. this

WPS is a must-have computer software for many users. Regular updates to new versions can allow users to get a better user experience and more features. So how to upgrade the wps version? There are three main methods for upgrading wpsoffice. Let’s take a look below. Method 1: Download the new version from the official website You can download the latest version of the installation package from the WPSOffice official website. After entering the WPSOffice official website (https://www.wps.cn/), click the "Download" button, select the version you need to download, and then follow the prompts to install it. Note: When installing a new version, you need to uninstall the old version, otherwise it will cause software conflicts and prevent normal use. Method 2: In WPSOf

On June 21, Huawei Developer Conference 2024 (HDC2024) gathered again in Songshan Lake, Dongguan. At this conference, the most eye-catching thing is that HarmonyOSNEXT officially launched Beta for developers and pioneer users, and comprehensively demonstrated the three "king-breaking" innovative features of HarmonyOSNEXT in all scenarios, native intelligence and native security. HarmonyOSNEXT native intelligence: Opening a new AI era After abandoning the Android framework, HarmonyOSNEXT has become a truly independent operating system independent of Android and iOS, which can be called an unprecedented rebirth. Among its many new features, native intelligence is undoubtedly the new feature that can best bring users intuitive feelings and experience upgrades.
