使用元素时Paginator错误

时间:2014-10-24 21:05:30

标签: cakephp pagination element paginator

我有评论的新闻。我想对评论进行分页,但我有这样的错误:

Notice (8): Undefined index: count [CORE\Cake\View\Helper\PaginatorHelper.php, line 646]

当然,我没有看到数字,链接等。

你知道如何解决这个问题吗? 谢谢!

组件:

public function viewFromNewsId($news_id = null) {
$this->NewsComment->recursive = 0;
$this->Paginator->settings = array('conditions' => array('NewsComment.news_id' => $news_id, 'NewsComment.is_active' => '1'), 'limit' => 5, 'order' => array('NewsComment.id' => 'desc'));
$newsComments = $this->Paginator->paginate('NewsComment');
if (isset($this->params['requested'])){
return $newsComments;
}
}

元素:

$newsIdFromUrl = $this->params['pass'][0];
$newsComments = $this->requestAction("newsComments/viewFromNewsId/$newsIdFromUrl");
foreach($newsComments as $newsComment):
$this->App->showNewsComment($newsComment);
endforeach;
echo $this->Paginator->counter('Liczba newsów: {:count} | ');
echo $this->Paginator->prev('<< wstecz', null, null, array('class' => 'disabledText'));
echo $this->Paginator->numbers(array('separator' => ' ', 'before' => ' | ', 'after' => ' | ', 'modulus' => '10'));
echo $this->Paginator->next('dalej >>', null, null, array('class' => 'disabledText'));
echo "<br />";

查看: echo $this->element('newsViewComments');

1 个答案:

答案 0 :(得分:0)

我自己找到答案;)

检查一下 - 也许有人会用这个。我知道有很多人有同样的问题。

答案: 只是不使用元素,在控制器中编辑视图功能,如下所示:

public function view($id = null) {
$this->Paginator->settings = array('conditions' => array('NewsComment.news_id' => $id), 'limit' => 5, 'order' => array('NewsComment.id' => 'desc'));
$newsComments = $this->Paginator->paginate('NewsComment');


$options = array('conditions' => array('News.' . $this->News->primaryKey => $id));
$news = $this->News->find('first', $options);
$this->set(compact('news', 'newsComments'));
}

如何,你的view.ctp中有两个变量: 第一个$news - 包含标题和文字等新闻数据,第二个 $newsComments与foreach和分页一起使用

但是,请记住模型中的正确关联。

相关问题