Do a <? pr($categories); ?> in app/views/categories/index.thtml (cake
1.1) so you can see the nested array.

IMHO sub category is a model of kind "category":

Categories {id, cat_id, name, description}. If the category is a root-
category, then cat_id can be 0 or another value. Thus you have a
recursive model (the same idea behing the threaded posts in a forum. I
used this kind of trick in some php non-cake applications, anybody
knows is there are any problem with this kind of model in cake?

Saludos and sorry for my poor english

On 8 jun, 10:54, in-sanity <[EMAIL PROTECTED]> wrote:
> Hi all!
>
> I've been trying for a while now to build a menu that looks like this:
>
> Category 1
> subcat1, subcat2, subcat3...
>
> Category 2
> subcat2.1, subcat2.2, subcat3.3...
>
> and so on...
>
> I can't seem to get around the nested array returned by the
> controller ...
> categories controller code:
>
> class CategoriesController extends AppController {
>
>         var $name = 'Categories';
>
>         function index(){
>                 $this->set('categories', $this->Category->findAll());
>         }
>
> }
>
> the category model looks like this:
> class Category extends AppModel {
>
>         var $name = 'Category';
>         var $hasMany = array('Subcategory' =>
>                          array('className'     => 'Subcategory',
>                                'conditions'    => '',
>                                'order'         => '`Subcategory`.`id`
> ASC',
>                                'dependent'     => true,
>                                'foreignKey'    =>
> '`cat_id`'
>                               ),
>                          'Article' =>
>                          array('className'     => 'Article',
>                                'conditions'    => '',
>                                'order'         => '`Article`.`created`
> DESC',
>                                'limit'         => '3',
>                                'dependent'     => true,
>                                'foreignKey'    =>
> '`cat_id`'
>                               )
>                   );
>
> }
>
> and the tables form the database look like this:
>
> CREATE TABLE `categories` (
>   `id` int(11) NOT NULL auto_increment,
>   `name` varchar(50) collate latin1_general_ci NOT NULL,
>   `description` varchar(255) collate latin1_general_ci NOT NULL,
>   PRIMARY KEY  (`id`)
> ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
> AUTO_INCREMENT=2 ;
>
> CREATE TABLE `subcategories` (
>   `id` int(11) NOT NULL auto_increment,
>   `cat_id` int(11) NOT NULL,
>   `name` varchar(50) collate latin1_general_ci NOT NULL,
>   `description` varchar(255) collate latin1_general_ci NOT NULL,
>   PRIMARY KEY  (`id`)
> ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
> AUTO_INCREMENT=3 ;
>
> Help me!
>
> Thanks in advance for your ideas and guidance.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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