用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3884|回复: 2
收起左侧

$this->db->offset() 有这个?

[复制链接]
发表于 2011-7-21 22:10:23 | 显示全部楼层 |阅读模式
偶然在STBlog中看到这行,比如:

PHP复制代码
 
    /**
     * 获取内容列表
     *
     * @access public
     * @param string  $type              内容类型
     * @param string  $status             内容状态
     * @param int       $author_id         作者ID (optional)
     * @param int       $limit             条数      (optional)
     * @param int       $offset             偏移量 (optional)
     * @param int       $category_filter     需要过滤的栏目ID (optional)
     * @param int       $title_filter     需要过滤的标题关键字 (optional)
     * @param bool    $feed_filter        是否显示在feed里面 (optional)
     * @return array  内容列表信息
     */

    public function get_posts($type = 'post', $status = 'publish', $author_id = NULL, $limit = NULL, $offset = NULL, $category_filter = 0, $title_filter = '', $feed_filter = FALSE)
    {
        $this->db->select('posts.*, users.screenName');
        $this->db->join('users','users.uid = posts.authorId');
       
        //type
        if($type && in_array($type, $this->_post_type))
        {
            $this->db->where('posts.type', $type);
        }
       
        //status
        if($status && in_array($status,$this->_post_status))
        {
            $this->db->where('posts.status', $status);
        }
       
        //author
        if(!empty($author_id))
        {
            $this->db->where('posts.authorId', intval($author_id));
        }
       
        //category filter
        if(!empty($category_filter))
        {
            $this->db->join('relationships','posts.pid = relationships.pid','left');
            $this->db->where('relationships.mid', intval($category_filter));
        }
       
        //title filter
        if(!empty($title_filter))
        {
            $this->db->like('posts.title', $title_filter);
        }
       
        //feed filter
        if($feed_filter)
        {
            $this->db->where('allowFeed', 1);
        }
       
        $this->db->order_by('posts.created','DESC');
       
        //limit
        if($limit && is_numeric($limit))
        {
            $this->db->limit(intval($limit));
        }
       
        //offset
        if($offset && is_numeric($offset))
        {
            $this->db->offset(intval($offset));
        }
       
        return $this->db->get(self::TBL_POSTS);
    }
 
复制代码


怎么手册里没有    $this->db->offset() ?

发表于 2011-7-22 08:49:24 | 显示全部楼层
Software API可分为两类,documented与undocumented。

Documented API是官方发布,属权威性,极少会改变。即使要改,一般会保留backward compatibility。因其它开发者倚靠官方发布的API进行开发,任何API改动皆会对大量原有软件产生影响,修改补救的工作量可不是开玩笑的。真的必须要改变时会有大量工作配合以减低影响。

Undocumented API是存在可用的,但官方未曾发布,使用的话,各安天命,将来变了而出错,怪不得人。官方并无任何责任!

一般非不得意才会使用Undocumented API。

$this->db->offset();可在database/DB_active_rec.php内找到,属Active Record的undocumented API。

评分

参与人数 1威望 +1 收起 理由
kissgxd + 1 赞一个!

查看全部评分

 楼主| 发表于 2011-7-22 16:33:36 | 显示全部楼层
燃雲 发表于 2011-7-22 08:49
Software API可分为两类,documented与undocumented。

Documented API是官方发布,属权威性,极少会改变。 ...

懂了
谢谢

本版积分规则