CakePHP2.x is upgraded to 3.0, and cakephp2.x is upgraded to 3.0. CakePHP2.x upgrade 3.0, cakephp2.x upgrade 3.0CakePHP2.x3.x upgrade shoushunyi, Controller Layer 1. find (list) original 2. in x, this method uses fields in the specified option to implement keyvalue3 CakePHP 2.x upgrade 3.0, and cakephp2.x upgrade 3.0.
CakePHP 2.x => 3.x upgrade
I. Controller layer
1. find ('list ')
In the original 2. x, this method uses 'fields' in the specified option to implement key => value
3. x is replaced by 'keyfield' and 'valuefield 'in option, and the return value must be converted using toArray ().
2. find ('first '), find ('count ')
3. x has completely discarded the two parameters and replaced them with find ()-> first () and find ()-> count ().
3. when you find a joined table, you must add the 'containing' attribute. by default, the table is not associated with Cake 3.x.
4. findById
**? No documentation found? **
In 2.x, the findById format is ($ id, array $ fields)
3. there may be only one parameter ($ id) in array x. You need to use the select (array $ fields) method to filter data.
5. Component-> initialize ()
2. x get the Controller that calls this Component through initialize (Controller $ Controller)
3. x changes the initialize parameter to initialize (array $ config), which is obtained through $ controller = $ this-> _ registry-> getController ();
6. SessionComponent
3. x discards the Component and replaces it with $ this-> request-> session ().
II. Model layer
1. Associations
2. x implement Association by defining attributes
3. x needs to be implemented by calling $ this-> belonsto, $ this-> hasMany, $ this-> belongstoations, $ this-> addAssociations and other methods in the initialize method in the Table.
2. Validation
2. x implement data verification by defining the validate attribute
3. x needs to define the validationDefault (Validator $ validator) method in the Table to implement
3. virtualFields
3. x discards this attribute. to use this attribute, you need to append the method to Entity.
For example, you need Table A to define the virtual field full_name.
First, add protected function _ getFullName () to the Entity of Table ()
Add full_name to $ _ accessible.
After A-> find is used, the value can only be obtained through object-> property, and cannot be obtained through array.
4. field ()
**? No documentation found? **
3. x may be discarded. this method can be replaced by the get () method.
5. ClassRegistry: init ()
3. x replace the method with TableRegistry: get ().
6. Mysql alias settings
2. x only needs to add as to the fields attribute, for example, 'fields' => array ('Id as table_id ')
3. if an alias is defined, add a key such as 'fields' => ['Table _ id' => 'id'].
3. View layer
(View layer, move from the View folder of 2.x to the Template of 3.x)
1. $ this-> Html-> url
Replace $ this-> Url-> build in 3.x
IV. Bug
1. Associations
If you want to specify fields for table join queries in hasales, you must add the? in fields ???
This upgrade will continue to be updated ~~~~~~
Http://www.bkjia.com/PHPjc/984441.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/984441.htmlTechArticleCakePHP 2.x upgrade 3.0, cakephp2.x upgrade 3.0 CakePHP 2.x = 3.x upgrade hand shun 1, Controller Layer 1. find ('list') original 2. in x, this method uses 'fields' in the specified option to implement key = value 3...