Friday, January 30, 2009

Re: Using pagination inside elements

Some progress: adding the paginator helper to the helpers array avoid
the "call to a memeber function in a non-object", but the paginator
doesn't paginate anything. In each helper call an undefined index
error is shown.

Notice (8): Undefined index: pageCount [CORE\cake\libs\view\helpers
\paginator.php, line 476]
Notice (8): Undefined index: count [CORE\cake\libs\view\helpers
\paginator.php, line 416]
...

Any idea?

Note that the paginator helper must be added to the items controller,
not the item_comments controller.

On Jan 30, 1:10 am, "dr. Hannibal Lecter" <lecter...@gmail.com> wrote:
> This is just a wild guess, but perhaps it is not applied when you're
> using requestAction()? It is (if I understand correctly) a separate
> request as far as cake is concerned.
>
> Try adding the paginator manually in your controller, and if that
> doesn't work maybe someone else will offer more help.
>
> On Jan 29, 10:06 pm, Xoubaman <xouba...@gmail.com> wrote:
>
> > I edited some code to make it more readable in the group, looks like
> > that is a misstip. The requestAction works fine, in fact if I comment
> > all $paginator mentions the foreach shows the expected results.
>
> > The doc reads that setting var $paginate and using the method paginate
> > () automatically adds the PaginationHelper.
>
> > On Jan 29, 8:50 pm, "dr. Hannibal Lecter" <lecter...@gmail.com> wrote:
>
> > > Well, maybe you didn't include the PaginatorHelper in your app.
>
> > > Other thing which seems odd to me is that your controller is
> > > "ItemsComments", but in your element you're calling $this->requestAction('items/get_comments/'.$id). Is 'items/get_comments/'
>
> > > properly mapped to ItemsComments::index()?
>
> > > On Jan 29, 7:22 pm, Xoubaman <xouba...@gmail.com> wrote:
>
> > > > I'm trying to code an element that shows the comments about a certain
> > > > item, but when I'm using the paginator helper i get a "Fatal error:
> > > > Call to a member function numbers() on a non-object in[...]" message.
>
> > > > Searching the group i found that some users had the same problem, but
> > > > never received a valid answer, so... let's try again.
>
> > > > The code:
>
> > > > CONTROLLER:
>
> > > > class ItemsCommentsController extends AppController {
>
> > > >         function index($id = null) {
> > > >                 if (!$id) {
> > > >                         $this->Session->setFlash(__('Invalid Item.', true));
> > > >                         $this->redirect(array('action'=>'index'));
> > > >                 }
> > > >                 $comments = $this->paginate('ItemComment', array
> > > > ('ItemComment.item_id =' => $id));
>
> > > >                 if(isset($this->params['requested'])) { return $comments;}
>
> > > >                 $this->set('comments', $comments);
> > > >         }
>
> > > > }
>
> > > > VIEW:
>
> > > > echo $this->element('item_comments',array('id'=>$item['Item']['id']));
>
> > > > ELEMENT:
>
> > > > <?php $comments = $this->requestAction('items/get_comments/'.$id); ?>
> > > > <?php
> > > >   echo $paginator->numbers(); ?>
> > > >   echo $paginator->prev('« Previous ', null, null, array('class' =>
> > > > 'disabled'));
> > > >   echo $paginator->next(' Next »', null, null, array('class' =>
> > > > 'disabled'));
> > > >   foreach ($comments as $comment){
> > > >      echo '<br />User: '.$comment['User']['username']).'<br />';
> > > >      echo $comment['ItemComment']['content'].'<br />';
> > > >   }
> > > > ?>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: