显示与CakePHP相关的元素

时间:2015-09-22 21:48:12

标签: cakephp-3.0

我有一个包含很多产品的页面,我想只显示与用户和区域All具有相同区域的页面,所以如果我有一个用户哪个区域是日本,那么用户只需要看到带有区域的产品全部和日本。

如何展示具有该矩形的产品?

我不知道是否必须在控制器上的分页上执行此操作。

当我搜索搜索功能时,我做了一些显示同一区域的东西,但我不能在索引功能上做同样的事情

修改

我发现如何使用查询设置网址以显示我想要的内容,但现在分页不起作用,它会在一个页面上显示所有结果,这是我的索引功能:

    public function index()
{
    $this->paginate = [
        'contain' => ['Languages', 'Categories', 'Users'],
        'limit' => 2
    ];
    $this->set('multimedia', $this->paginate($this->Multimedia));
    $this->set('_serialize', ['multimedia']);

            $multimedia = array();

    if (!empty($this->request->query)) {

        $country_id = $this->request->query['country_id'];

        $conditions = array(
           'AND' => array(
               'OR' => array(
                   'Multimedia.country_id' => $country_id,
                ),
                'AND' => array(
                )
            )
        );

        if ($country_id) $conditions['conditions']['or']['Multimedia.country_id'] = $country_id ;

        $multimedia = $this->Multimedia->find('all', $conditions);
    }
    $this->set('multimedia', $multimedia);

    $languages = $this->Multimedia->Languages->find('list', ['limit' => 200]);
    $categories = $this->Multimedia->Categories->find('list', ['limit' => 200]);
    $users = $this->Multimedia->Users->find('list', ['limit' => 200]);
    $multimedia_types = $this->Multimedia->Multimedia_types->find('list', ['limit' => 200]);
    $this->set(compact('multimedia', 'languages', 'categories', 'users', 'multimedia_types'));
    $this->set('_serialize', ['multimedia']);

}

1 个答案:

答案 0 :(得分:0)

您正在使用$multimedia = $this->Multimedia->find('all', $conditions),所以当然您获得了所有结果。改为get paginated results,用

替换该行
$this->paginate['conditions'] = $conditions;
$multimedia = $this->paginate($this->Multimedia);