konto usunięte

Temat: Paginator w elementach

Witajcie, niestety nigdzie nie znalazłem odpowiedzi na mój problem :(
Mam news, do którego dodawane są komentarze, w view newsa dodaję element z komentarzami, komentarze chciałbym podzielić na strony i cały czas otrzymuję komunikaty typu Notice (8): Undefined index: count [CORE\Cake\View\Helper\PaginatorHelper.php, line 646]

Może będziecie wstanie mi pomóc?
Z góry dzięki!

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

Element:
$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 />";

I view:
echo $this->element('newsViewComments');
Bartek Naski

Bartek Naski CakePHP developer

Temat: Paginator w elementach

ciężko to zaczaić co wkleiłeś, ale może zamiast return daj $this->set(compact('newsComments'))
a jak chcesz tą paginację po ajax to się trochę inaczej robi, paginator ma to w sobie
Bartek Naski

Bartek Naski CakePHP developer

Temat: Paginator w elementach

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' => 'NewsComment.id desc'
);
$newsComments = $this->Paginator->paginate('NewsComment');
$this->set(compact('newsComments'));
}

element
$this->Paginator->options(array(
'update' => '#iakis_id_div',
'evalScripts' => false
));
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 $this->Js->writeBuffer();

i pytasz jak do widoku, bez requestTen post został edytowany przez Autora dnia 30.10.14 o godzinie 17:48
Bartek Naski

Bartek Naski CakePHP developer

Temat: Paginator w elementach

a tak byłoby po twojemu z request action

controller
public function viewFromNewsId1() {
$this->Article->recursive = 0;
$this->Paginator->settings = array(
'fields' => array('Article.id'),
'conditions' => array(
// 'Article.id' => $news_id,
'Article.active' => '1'),
'limit' => 5,
'order' => 'Article.id desc'
);
$newsComments = $this->Paginator->paginate('Article');
return $newsComments;
}

elements

<div id="iakis_id_div">
<?php
foreach ($newsComments as $cos) {
echo $cos['Article']['id'] . '<br>';
}
$this->Paginator->options(array(
array('url' => array('controller' => 'utils', 'action' => 'viewFromNewsId1')),
'update' => '#iakis_id_div',
'evalScripts' => false
));
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 $this->Js->writeBuffer();
?>
</div>

tylko zmień sobie Article na swoje, bo zrobiłem sobie tescik u siebie pod swoją baze
http://cakephp.com.pl/utils/viewFromNewsId

konto usunięte

Temat: Paginator w elementach

Dzięki :)
Właśnie widzę jak działają powiadomienia na goldenline... dopiero teraz zobaczyłem, że odpowiedziałeś.
Nie zaglądałem bo właśnie zrobiłem to po widoku i jest git :)
Bartek Naski

Bartek Naski CakePHP developer

Temat: Paginator w elementach

:)

Następna dyskusja:

Paginator w elementach po r...




Wyślij zaproszenie do