1

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

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');

4

1 回答 1

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 和分页

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

于 2014-10-28T19:13:02.843 回答