带过滤器和多个视图的控制器

时间:2017-09-26 14:11:41

标签: cakephp model-view-controller filtering

在我的控制器中我有两个函数indexarchiv 在两个函数中我都有相同的过滤条件集,但对于archiv函数我使用索引视图。如何结合render-function设置条件。你有任何关于如何解决这个问题的提示

public function index() {
    ...
    $this->set('events', $this->Paginator->paginate($cond));

-

public function archiv() {

    ...
    $this->render('index');     // reuse index view

    // is not working
    // $this->set('events', $this->Paginator->paginate($cond));

编辑:如果我复制视图index.cpt,并注释$this->render并取消注释档案的最后一行,它可以正常工作,但我宁愿只保留一个视图,因为archiv始终与index

相同

1 个答案:

答案 0 :(得分:1)

您应该在调用render函数之前设置变量:

public function archiv() {

...
// this should work now
$this->set('events', $this->Paginator->paginate($cond));
$this->render('index');     // reuse index view
相关问题