简体   繁体   English

如何在焦炭中过滤流条目驱动程序的函数get_entries()返回的结果?

[英]How to filter a result returned by a function get_entries() of a stream entries driver in pyrocms?

I have a stream/table named profiles . 我有一个名为profiles的流/表。 All of its column are stream-fields. 它的所有列都是流字段。 I am trying to restrict the result returned by the the function, get_entries() depending on some criteria. 我试图根据某些条件来限制函数get_entries()返回的结果。 Below is my code: 下面是我的代码:

    $data = [
        'stream'    => 'profiles',
        'namespace' => 'users',
        'where'     => 'user_id = 3'     // lets say, this is my criteria
    ];

    $row = $this->streams->entries->get_entries($data); // returns empty 

The varaible, $row resulted in empty array. 变量$row导致数组为空。 Although there is one row in table, profiles where user_id is 3. I have read the documentation of pyrocms and it pretty much says the exact way to use the where clause (just like above). 尽管表中只有一行,但profiles user_id是3。我已经阅读了pyrocms的文档,并且几乎说了使用where子句的确切方法(就像上面一样)。

NOTE: I have also tried writing like 注意:我也尝试过像

'where' => 'profiles.user_id = 3'` 'where'=>'profiles.user_id = 3'`

joy !to avoid table conflict. 喜悦!避免表冲突。 Still no 仍然没有

But when I write the code like this: $row = $this->streams->entries->get_entries($query); 但是当我这样编写代码时:$ row = $ this-> streams-> entries-> get_entries($ query);

        $query = [
            'stream'    => 'profiles',
            'namespace' => 'users'     
        ];
        // No where clause this time

        $row = $this->streams->entries->get_entries($query);

This time $row returns all rows including the row with user id 3. 这次$ row返回所有行,包括用户ID为3的行。

I am unable to use the where clause in get_entries in a right way. 我无法正确使用get_entries中的where子句。 I might have done some mistake. 我可能做错了。 Help me out guyz 帮我盖伊

NOTE: I am using community edition. 注意:我正在使用社区版。

I think this might be due to a bug (well, not a bug, but a feature that doesn't work as intended). 我认为这可能是由于一个错误(嗯,不是一个错误,而是一个功能无法按预期工作)。

If I'm intentionally issue a wrong query, the sql query output is 如果我故意发出错误的查询,则sql查询输出为

SELECT [ ... ] LEFT JOIN `default_profiles` as `profiles` ON `profiles`.`user_id`=`default_profiles`.`created_by` WHERE (user_id` = 1) ORDER BY `default_profiles`.`created` DESC

Here you see that PyroCMS tries to lookup the data for the "created_by" field. 在这里您可以看到PyroCMS尝试查找“ created_by”字段的数据。 And that doesn't work in this case. 在这种情况下,这是行不通的。

If you disable the 'created_by' field, you should get the correct row: 如果您禁用“ created_by”字段,则应获得正确的行:

$this->streams->entries->get_entries(
  array(
    'stream' => 'profiles',
    'namespace' => 'users',
    'where' => 'user_id = 3',
    'disable' => 'created_by'
  )
);

It would be great if you could file an issue on the pyrocms github page. 如果您可以在pyrocms github页面上提交问题,那就太好了。 If you won't I'll do it in the next few days. 如果您不愿意,我会在接下来的几天内完成。

Model 模型

public function get_entries($table, $where) {
        $this->db->select('*');
        $this->db->from($table);
        foreach ($where as $key => $value) {
            $this->db->where($key, $value);
        }
        $this->query = $this->db->get();
        foreach ($this->query->result_array() as $row) {
            $array1[] = $row;
        }
        if ($this->query->num_rows() == 0)
            return false;
        else
            return $array1;
    }

call this model function as 将此模型函数称为

$row = $this->streams->entries->get_entries('profiles',array('user_id '=>3));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM