In the application of http://www.aliyun.com/zixun/aggregation/17799.html "> development process, the use of the most operations or data query operations, by virtue of the thinkphp of the consistent operation of the characteristics, Can make query operations more elegant and clear, however, the new naming range feature defines a series of query packages for model operations, making it easier for you to query the data.
Defining attributes
To use the naming range feature, the _scope attribute definition of the model class and the use of the scope consistent operation method are mainly involved. We first define the _scope attribute:
Class Newsmodel extends Model {protected $_scope = Array (//named range normal ' normal ' =>array (' WH Ere ' =>array (' status ' =>1),///Name Range latest ' latest ' =>array (' order ' => ') create_tim E DESC ', ' limit ' =>10,); }
The _scope property is an array in which each array item represents the definition of a named range, and the defined format of the named range is:
' Named range ID ' =>array (' property 1 ' => ' value 1 ', ' attribute 2 ' => ' value 2 ', ...)
Named range ID: can be any string that identifies the name of the currently defined named range. The properties supported by the named range include:
Where Query Condition field query field Order result sort table table name limit result limit page results paging having queries Group group query lock query lock distinct Unique query cache query caching the definition of each named range can include one or more of these properties.
Method calls
Once the property definition is complete, the next step is to invoke the named range using the scope method, and each invocation of a named range is equivalent to executing the consistent operation of the associated operation options defined in the named scope.
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.