使用Stream Entries时获取两个查询

时间:2013-07-17 15:47:51

标签: codeigniter pyrocms

我有这段代码:

public function index($offset = 0) {
    $params = array(
        'stream' => 'companies',
        'namespace' => 'companies',
        'paginate' => 'yes',
        'pag_segment' => 3
    );

    // Build regular expression to match items from DB
    $regexp = "'^[" . strtolower($this->uri->segment(4)) . strtoupper($this->uri->segment(4)) . "]'";
    $params['where'] = "name REGEXP " . $regexp;

    $entries = $this->streams->entries->get_entries($params);

    $this->template->set('items', $entries)->build('index');
}

我不知道为什么,但我收到两个查询,请参阅以下详细信息:

  

0.0008 SELECT default_companies。*,cb_users.id as created_by || user_id,cb_users.email as created_by || email,cb_users.username as   created_by || username,profiles.display_name as   created_by || display_name FROM default_companies LEFT JOIN   default_users as cb_users ON cb_users.id = default_companies.created_by   LEFT JOIN default_profiles作为配置文件ON   profiles.user_id = default_companies.created_by WHERE(名称REGEXP   '^ [mM]')ORDER BY default_companiescreated DESC

此查询是正确的,它会生成有效记录,但是......

  

0.0008 SELECT default_companies。*,cb_users.id as created_by || user_id,cb_users.email as created_by || email,cb_users.username as   created_by || username,profiles.display_name as   created_by || display_name FROM default_companies LEFT JOIN   default_users as cb_users ON cb_users.id = default_companies.created_by   LEFT JOIN default_profiles作为配置文件ON   profiles.user_id = default_companies.created_by WHERE(名称REGEXP   '^ [mM]')ORDER BY default_companiescreated DESC LIMIT 10 OFFSET   4

第二个查询(不知道它为什么被执行)不会返回任何值,因为OFFSET参数因此我的视图始终为空。这有什么不对?我错过了什么?我正在运行PyroCMS 2.2.1社区

1 个答案:

答案 0 :(得分:3)

第一个查询在第658行的system / cms / modules / streams_core / models / rows_m.php中执行。它简单计算流表中所有记录的总和,以获得正确的分页。

但是我不确定,为什么它设置了4的偏移量。如果缺少它,应该设置为0.

您应该尝试将$ offset参数添加到get_entries函数的$ params数组中,并检查接下来会发生什么。