This article mainly introduces cakephp framework model function definition method, combined with the specific query function example to analyze the cakephp framework model function definition method, the need for friends can refer to the following
This paper describes the definition method of CakePHP framework model function. Share to everyone for your reference, as follows:
In cakephp, the architecture of MVC is clear, and in actual projects I find that there are still a lot of people who like to stack functions in a controller, and that's fine, but, as a mega-project of millions of rows, This kind of contrary to the idea of MVC, although it may temporarily bring convenience to the structure of the program, but in the long run, is absolutely impossible to take!
We should define some of the functions commonly used in the system in the model, especially the purely data processing functions and query functions:
For example, in a blog like the following conditions query:
/*** Blog based on conditions get corresponding field result set * * @Param array conditions* array fields* @Return array**/function Getblogsbycon ($conditions = Array (), $fields = null) { return $this->find (' All ', array ( ' conditions ' = IFE (COUNT ($conditions) > 0, am (Array (' blog '), ' status ' = 1 '), $conditions), Array (' blog '. ' Status ' = 1 ')), ' Fields ' = = $fields, ' order ' = ' Blog '. ' Created ' DESC ', ' page ' =>1, ' recursive ' =>0);}