CakePHP 2.x upgrade 3.0,cakephp2.x Upgrade 3.0
CakePHP 2.x + 3.x upgrade hand Shun
First, controller layer
1.find (' list ')
In the original 2.x, this method is implemented by specifying the ' fields ' in option Key=>value
3.x is replaced with ' Keyfield ' and ' valuefield ' in option, the return value needs to be converted with toarray ()
2.find (' first '), find (' count ')
These two parameters have been completely discarded in 3.x and replaced with Find ()->first () and find ()->count ()
3.find you must add a ' contain ' property when querying the associated table, Cake 3.x does not associate tables together by default
4.findById
* * Not found the relevant documents? * *
2.x in FindByID format ($id, array $fields)
There may be only one parameter ($id) in 3.x, and the data needs to be filtered by the Select (array $fields) method
5.component->initialize ()
2.x gets the controller that invokes the component by Initialize (Controller $Controller)
3.x changed the Initialize parameter to initialize (array $config), via $controller = $this->_registry->getcontroller ();
6.SessionComponent
3.x discarded the component and instead replaced it with $this->request->session ()
Second, model layer
1.Associations
2.x implementing associations by defining attributes
3.x needs to call $this->belongsto, $this->hasmany, $this->belongstomany, $this, in the Initialize method in the table Addassociations and other methods to achieve
2.Validation
2.x data validation by defining validate properties
3.x needs to define the Validationdefault (Validator $validator) method in the table to implement the
3.virtualFields
This attribute is deprecated in 3.x and needs to be appended to the entity to be used.
For example, you need a table to define a virtual field full_name
First, add protected function _getfullname () to the entity of Table A.
Then add the full_name to the $_accessible
This value can only be obtained by Object->property when A->find is used, and cannot be obtained by means of an array
4.field ()
* * Not found the relevant documents? * *
3.x may be deprecated this method can be replaced with the Get () method
5.classregistry::init ()
3.x obsolete This method needs to be replaced with Tableregistry::get ()
6.Mysql alias settings
2.x only needs to include as in the fields attribute as ' Fields ' =>array (' id as table_id ')
3.x if you define an alias, you need to add key such as ' Fields ' =>[' table_id ' + ' ID ']
Third, view layer
(view layer, moving from the 2.x view folder to the 3.x template)
1. $this->html->url
3.x replacement with $this->url->build
Four, the Bug
1. Associations
Hasmany The table is associated with a query, if you need to specify fields, you must add the associated key in the fields???
This upgrade hand will continue to update in ~~~~~~
http://www.bkjia.com/PHPjc/984441.html www.bkjia.com true http://www.bkjia.com/PHPjc/984441.html techarticle cakephp 2.x upgrade 3.0,cakephp2.x Upgrade 3.0 cakephp 2.x = 3.x upgrade hand shun, controller layer 1.find (' list ') in the original 2.x in the method by specifying the ' Fields ' to achieve Key=value 3 ...