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


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

我有一个名为profiles的流/表。它的所有列都是流字段。我试图根据一些条件来限制函数get_entries()返回的结果。以下是我的代码:

    $data = [
        'stream'    => 'profiles',
        'namespace' => 'users',
        'where'     => 'user_id = 3'     // lets say, this is my criteria
    ];
    $row = $this->streams->entries->get_entries($data); // returns empty 

可变$row导致空数组。尽管表中有一行,profiles,其中user_id是3。我已经阅读了pyrocms的文档,它几乎说明了使用where子句的确切方式(就像上面一样)。

注意:我也试过像一样写作

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

快乐!以避免表冲突。仍然没有

但是当我这样写代码时:$row=$this->streams->entries->get_entries($query);

        $query = [
            'stream'    => 'profiles',
            'namespace' => 'users'     
        ];
        // No where clause this time
        $row = $this->streams->entries->get_entries($query);

这次$row返回所有行,包括用户id为3的行。

我无法正确使用get_entries中的where子句。我可能做错了什么。帮帮我伙计们

注意:我使用的是社区版。

我认为这可能是由于一个错误(好吧,不是一个错误,而是一个无法按预期工作的功能)。

如果我故意发出错误的查询,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

在这里,您可以看到PyroCMS试图查找"created_by"字段的数据。这在这种情况下是行不通的。

如果您禁用"created_by"字段,您应该得到正确的行:

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

如果你能在pyrocms github页面上提交一个问题,那就太好了。如果你不愿意,我会在接下来的几天里做。

型号

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;
    }

将此模型函数称为

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