<?php
namespace GoodsModel;
use ThinkModel;
class GoodsModel extends Model
{
protected $_scope = array(
'normal' => array(
'where' => array('is_on_sale' => 1),
'order' => array('id' => 'desc')
),
'latest' => array(
'order' => 'create_time',
'where' => 'is_on_sale=1'),
),
'default' => array(
'order' => "id desc"
),
);
public function test()
{
$this->scope()->select();//1.使用默认定义的范围default
$this->scope('normal')->select();//2.使用nomal命名范围
$this->scope('normal,latest')->select();//3.使用nomal和latest范围
$this->normal()->select();//使用normal命名范围,同2
$this->normal(array('limit'=>5))->select();//使用normal命名范围,加上limit 5的条件,同连贯方法limit一样
}
}