How to display Child categories of self-pointed Model?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to display Child categories of self-pointed Model?

Apprentice-2

Hi all,

I have a Model Category:

----------------------------------------
<?php
class Category extends AppModel
{
        var $name = 'Category';
        var $validate = array(
                'name' => VALID_NOT_EMPTY,
                'description' => VALID_NOT_EMPTY,
        );

        //The Associations below have been created with all possible keys,
those that are not needed can be removed
        var $belongsTo = array(
                        'Categories' =>
                         array('className' => 'Category',
                                        'conditions' => '',
                                        'fields' => '',
                                        'order' => 'Categories.ord ASC',
                                        'foreignKey' => 'category_id',
                                        'counterCache' => ''),

        );

        var $hasMany = array(
                        'Categories' =>
                         array('className' => 'Category',
                                        'foreignKey' => 'category_id',
                                        'conditions' => '',
                                        'fields' => '',
                                        'order' => 'Categories.ord ASC',
                                        'limit' => '',
                                        'offset' => '',
                                        'dependent' => '',
                                        'exclusive' => '',
                                        'finderSql' => '',
                                        'counterSql' => ''),

                        'Post' =>
                         array('className' => 'Post',
                                        'foreignKey' => '',
                                        'conditions' => '',
                                        'fields' => '',
                                        'order' => '',
                                        'limit' => '',
                                        'offset' => '',
                                        'dependent' => '',
                                        'exclusive' => '',
                                        'finderSql' => '',
                                        'counterSql' => ''),

        );

}
?>
----------------------------------------

And the table that serves Category:
----------------------------------------
CREATE TABLE `categories` (
  `id` int(10) NOT NULL auto_increment,
  `category_id` int(10) NOT NULL default '0',
  `name` varchar(50) collate utf8_bin NOT NULL,
  `description` varchar(255) collate utf8_bin NOT NULL,
  `created` datetime NOT NULL,
  `modified` datetime NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `category_id` (`category_id`,`name`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin
COMMENT='Categories' AUTO_INCREMENT=8 ;
----------------------------------------
By doing:

$this('categories', $this->Category->findAll())

I can only display the Parent Category, which is containted in the
array $categories['Categories']

I don't know how to find, retrieve & display Child Categories. Please
give a hint.

Any help is appreciated. Thank you in advance!

Apprentice.


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

Reply | Threaded
Open this post in threaded view
|

RE: How to display Child categories of self-pointed Model?

Adrian Godong

You should change the name of the 'association'. E.g.:

...
        var $belongsTo = array(
                        'ParentCategory' =>
                         array('className' => 'Category',
...

And

...
        var $hasMany = array(
                        'ChildCategory' =>
                         array('className' => 'Category',
...

Good luck!

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf
Of Apprentice
Sent: 04 Nopember 2006 19:54
To: Cake PHP
Subject: How to display Child categories of self-pointed Model?


Hi all,

I have a Model Category:

----------------------------------------
<?php
class Category extends AppModel
{
        var $name = 'Category';
        var $validate = array(
                'name' => VALID_NOT_EMPTY,
                'description' => VALID_NOT_EMPTY,
        );

        //The Associations below have been created with all possible keys,
those that are not needed can be removed
        var $belongsTo = array(
                        'Categories' =>
                         array('className' => 'Category',
                                        'conditions' => '',
                                        'fields' => '',
                                        'order' => 'Categories.ord ASC',
                                        'foreignKey' => 'category_id',
                                        'counterCache' => ''),

        );

        var $hasMany = array(
                        'Categories' =>
                         array('className' => 'Category',
                                        'foreignKey' => 'category_id',
                                        'conditions' => '',
                                        'fields' => '',
                                        'order' => 'Categories.ord ASC',
                                        'limit' => '',
                                        'offset' => '',
                                        'dependent' => '',
                                        'exclusive' => '',
                                        'finderSql' => '',
                                        'counterSql' => ''),

                        'Post' =>
                         array('className' => 'Post',
                                        'foreignKey' => '',
                                        'conditions' => '',
                                        'fields' => '',
                                        'order' => '',
                                        'limit' => '',
                                        'offset' => '',
                                        'dependent' => '',
                                        'exclusive' => '',
                                        'finderSql' => '',
                                        'counterSql' => ''),

        );

}
?>
----------------------------------------

And the table that serves Category:
----------------------------------------
CREATE TABLE `categories` (
  `id` int(10) NOT NULL auto_increment,
  `category_id` int(10) NOT NULL default '0',
  `name` varchar(50) collate utf8_bin NOT NULL,
  `description` varchar(255) collate utf8_bin NOT NULL,
  `created` datetime NOT NULL,
  `modified` datetime NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `category_id` (`category_id`,`name`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin
COMMENT='Categories' AUTO_INCREMENT=8 ;
----------------------------------------
By doing:

$this('categories', $this->Category->findAll())

I can only display the Parent Category, which is containted in the
array $categories['Categories']

I don't know how to find, retrieve & display Child Categories. Please
give a hint.

Any help is appreciated. Thank you in advance!

Apprentice.




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

Reply | Threaded
Open this post in threaded view
|

Re: How to display Child categories of self-pointed Model?

Apprentice-2

Hi Adrian,

Thank you very much. I manganed to do so ;-)

Regards,
Apprentice.

On Nov 5, 1:02 am, "Adrian Godong" <[hidden email]> wrote:

> You should change the name of the 'association'. E.g.:
>
> ...
>         var $belongsTo = array(
>                         'ParentCategory' =>
>                          array('className' => 'Category',
> ...
>
> And
>
> ...
>         var $hasMany = array(
>                         'ChildCategory' =>
>                          array('className' => 'Category',
> ...
>
> Good luck!
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf
>
> Of Apprentice
> Sent: 04 Nopember 2006 19:54
> To: Cake PHP
> Subject: How to display Child categories of self-pointed Model?
>
> Hi all,
>
> I have a Model Category:
>
> ----------------------------------------
> <?php
> class Category extends AppModel
> {
>         var $name = 'Category';
>         var $validate = array(
>                 'name' => VALID_NOT_EMPTY,
>                 'description' => VALID_NOT_EMPTY,
>         );
>
>         //The Associations below have been created with all possible keys,
> those that are not needed can be removed
>         var $belongsTo = array(
>                         'Categories' =>
>                          array('className' => 'Category',
>                                         'conditions' => '',
>                                         'fields' => '',
>                                         'order' => 'Categories.ord ASC',
>                                         'foreignKey' => 'category_id',
>                                         'counterCache' => ''),
>
>         );
>
>         var $hasMany = array(
>                         'Categories' =>
>                          array('className' => 'Category',
>                                         'foreignKey' => 'category_id',
>                                         'conditions' => '',
>                                         'fields' => '',
>                                         'order' => 'Categories.ord ASC',
>                                         'limit' => '',
>                                         'offset' => '',
>                                         'dependent' => '',
>                                         'exclusive' => '',
>                                         'finderSql' => '',
>                                         'counterSql' => ''),
>
>                         'Post' =>
>                          array('className' => 'Post',
>                                         'foreignKey' => '',
>                                         'conditions' => '',
>                                         'fields' => '',
>                                         'order' => '',
>                                         'limit' => '',
>                                         'offset' => '',
>                                         'dependent' => '',
>                                         'exclusive' => '',
>                                         'finderSql' => '',
>                                         'counterSql' => ''),
>
>         );
>
> }
> ?>
> ----------------------------------------
>
> And the table that serves Category:
> ----------------------------------------
> CREATE TABLE `categories` (
>   `id` int(10) NOT NULL auto_increment,
>   `category_id` int(10) NOT NULL default '0',
>   `name` varchar(50) collate utf8_bin NOT NULL,
>   `description` varchar(255) collate utf8_bin NOT NULL,
>   `created` datetime NOT NULL,
>   `modified` datetime NOT NULL,
>   PRIMARY KEY  (`id`),
>   KEY `category_id` (`category_id`,`name`)
> ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin
> COMMENT='Categories' AUTO_INCREMENT=8 ;
> ----------------------------------------
> By doing:
>
> $this('categories', $this->Category->findAll())
>
> I can only display the Parent Category, which is containted in the
> array $categories['Categories']
>
> I don't know how to find, retrieve & display Child Categories. Please
> give a hint.
>
> Any help is appreciated. Thank you in advance!
>
> Apprentice.


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