Use paginate(). Obviously, that's not the answer you were looking for
but the long and the short of it is that Cake uses paginate() for
pagination. Try this query:

$items = $this->Item->find(
        'all',
        array(
                'conditions' => array(
                        'ItemContent.language_id' => $this->language_id
                ),
                'fields' => array(
                        'Item.id',
                        'Item.thumb',
                        'Item.module_id'
                )
                'group' => array('Item.id'),
                'contain' => array(
                        'ItemContent' => array(
                                'fields' => array(
                                        'ItemContent.name',
                                        'ItemContent.description',
                                        'ItemContent.item_id'
                                )
                        ),
                        'Module' => array(
                                'fields' => array(
                                        'Module.code'
                                )
                        )
                )
        )
);


You'll need to update your model associations by adding 'type' =>
'INNER'. If that works, it should be simple enough to use paginate().
Just leave out the condition array and add it within the action:

$this=>paginate['conditions'] = array('ItemContent.language_id' =>
$this->language_id);

The reason for that is you can use $this->language_id when defining a
class variable.

If you can't figure out how to turn your query() into a Cake find(),
you could look into using PEAR::pager as a vendor. I've used it before
(though not with a Cake app) and it works quite well.

http://www.alberton.info/pear_pager_tutorial_article_pagination.html

On Sun, Aug 16, 2009 at 5:45 PM, gjofum<[email protected]> wrote:
>
> I'd like to paginate $this->Model->query().
>
> For example I have this in my controller:
> $this->Item->query("SELECT Item.id, Item.thumb, ItemContent.name,
> ItemContent.description, Module.code FROM items AS Item INNER JOIN
> items_content AS ItemContent ON ItemContent.item_id = Item.id INNER
> JOIN modules AS Module ON Module.id = Item.module_id WHERE
> ItemContent.language_id = $this->language_id GROUP BY Item.id");
>
> Sometimes I need to use my own SQL code, because it's faster and
> sometimes I use tables that they don't have relations between them.
> But I don't to how to paginate it.
>
>
> >
>

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

Reply via email to