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
-~----------~----~----~----~------~----~------~--~---