The answer was actually really simple, I will post here in case it
helps anybody else.

I was trying to over-complicate things and pass a string to the
paginate conditions, when an array was needed. (Now I look back, a
string made no sense at all - but at least I'm learning!)

First step, is to do a find on the data in question (in this case I
used the variable $name), then use the following method to return the
children of the current ID:

// Grab parent id and children id:
$children = $this->Category->children($name['Category']['id']);

Next a new array is created to store the children's ID's:

// Loop through all of the children ID's and populate an array:
       foreach ($children as $child) {
        $child_array[] = $child['Category']['id'];
        }

I then added the current ID to the array:

// Add the current id to the array so current category results are
also included:
$child_array[] = $name['Category']['id'];

It was then just a case of adding the array to the paginate
conditions:

// Now setup paginating with all of the results:
$this->set('category', $this->paginate('Post', array('Category.id' =>
$child_array)));

So in conclusion, this is how I managed to paginate the tree behaviour
to include sub-categories as well. Hopefully this will help somebody
as I couldn't find much on this subject when searching.

On Jul 3, 5:08 pm, number9 <[email protected]> wrote:
> I have this array (condensed considerably so it is easier to read):
>
> Array
> (
>     [0] => Array
>         (
>             [Category] => Array
>                 (
>                     [id] => 1
>                 )
>
>         )
>
>     [1] => Array
>         (
>             [Category] => Array
>                 (
>                     [id] => 2
>                 )
>
>         )
> )
>
> What I want to do is access the "id" field, so I can use it as a
> paginate condition. Obviously I can call it like this: $variable['0']
> ['Category']['id'] but I need to use them all.
>
> I've tried messing about with for each loops and explode/implode. I
> managed to generate a string, seperated by a comma, but the variable
> didn't pass to the conditions. If I echoed the variable and copied and
> pasted that output into the condition it worked so I really am
> stumped.
>
> What I am trying to do is paginate the category page so that
> subcategories are included in the results as well (I am using tree
> behaviour).
>
> This is probably a lack of PHP understanding on my part, but I have
> always struggled with multi dimensional arrays and would appreciate
> help!
--~--~---------~--~----~------------~-------~--~----~
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