Introduction to the definition method of model function in cakephp framework

Source: Internet
Author: User
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);}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.