方便操作的命名范围scope

<?php
namespace Goods\Model;
use Think\Model;

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一样 } }

 

posted @ 2015-04-01 00:53  雪山飞猪  阅读(242)  评论(0编辑  收藏  举报