On Thu, Feb 24, 2011 at 9:36 AM, Mr.Jayesh <[email protected]> wrote: > Hi everyone, > > I am working on a project where I have set up a habtm for Categories. > I am using CakePHP 1.3 > The issue I am stuck is as under: > > I have a post form, where I have a Milti Select box for categories, so > I can select all the categories that the post belongs to and post it. > It works fine and all the relevant entries goes to the correct tables > (posts, categories, categories_posts). > > I am using Tree structure, so I have lft and rght set in the > categories table. > > I have two types forms field in different forms which is to be > populated by $categories: > 1. Dropdown - for creating new categories in system. > 2. Multi-Select - for posts > > and code of $controllers that I used is: > > Dropdown: $this->Category->generatetreelist (null, '{n}.Category.id', > '{n}.Category.cat_name', '...'); > This works fine and list is seem to be in hierarchy > > But problem is when I use similar code of Posts form, the category > list is just in plain list without hierarchy. Code used for that is: > > $categories = $this->Post->Category->generatetreelist (null, > '{n}.Category.id', '{n}.Category.cat_name', '...'); > > And in view: > echo $this->Form->input('Category.Category', array('label' => > 'Categories:', 'options' => $categories)); > > I want to get an hierarchical list of categories in the multi-select > field as set up in database. I tried many ways but no result. > Please advice.
Instead of calling generatetreelist() directly, you could call a custom method in Category model (which would call it). Then loop through the data adding $depth * $n NBSPs before each nested title/name, where $n is, eg. 2. er ... wait a sec. I just remembered that the method already does this for you: http://api.cakephp.org/class/tree-behavior#method-TreeBehaviorgeneratetreelist Note the spacer param. Make that ' ' and you're golden. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
