Re: Nested categories controller and routing
I solved this differently than suggested. This thread has my solution for those interested. http://groups.google.com/group/cake-php/browse_thread/thread/6c7cdd0cc5160a19/ac0466a2764df27f?lnk=gst&q=gremlin&rnum=2#ac0466a2764df27f --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Nested categories controller and routing
Hi Gremlin, I'm surprised this topic is still open. I would suggest: 1) get the passed args. 2) check if the last argument is an integer (if appropriate), if so the last but 1 is the category to search on, else the last argument is the category to search on. 3) for the category unbind all relationships except that for the parent 4) Set the recursive parameter on your category model appropriately 4) Find*All* categories named in step 2, and check that the parents recursively to get the right one Job done. You could also do the search the otherway around (FindByParent_id) again in a recursive loop, the choice should be made depending on what is going to result in less SQL. If you have vast numbers of categories I would recommend looking at using MPTT tables to store them, becuase in that way you have the possibility to get the right category in a single query. Something like (cat.lftsubsubcat.rght, subsubcat.name = "Subcat"), with any other additional logic you would need, such as checks on the intermediary categories, as appropriate. AD7six Please note: The manual/bakery is a good place to start any quest for info. The cake search (at the time of writing) erroneously reports less/no results for the google group. The wiki may contain incorrect info - read at your own risk (it's mainly user submitted) :) You may get your answer quicker by asking on the IRC Channel (you can access it with just a browser here: http://irc.cakephp.org). On Nov 2, 5:15 am, "gremlin" <[EMAIL PROTECTED]> wrote: > > this shouldn't be a problem. you just need to split the args in the > > categories index () function. You then build you complexity in there, > > perhaps limiting your depth to 4 /cat/subcat/subsubcat/idThe limit is > > absolutely not an option. I think perhaps a arg count on > the parameters could be used to set the recursive depth for the findall > query on the parent category relationship though. > > Anyone tell me if I am on the right track? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Nested categories controller and routing
> this shouldn't be a problem. you just need to split the args in the > categories index () function. You then build you complexity in there, > perhaps limiting your depth to 4 /cat/subcat/subsubcat/id The limit is absolutely not an option. I think perhaps a arg count on the parameters could be used to set the recursive depth for the findall query on the parent category relationship though. Anyone tell me if I am on the right track? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Nested categories controller and routing
> I can not pass the id into the controller in this case. I also can't > use a findall or findallbyname since the names of a category might not > be unique. I need to be able to handle an url like the following > examples. All of them. > > domain.ext/categories/books/ > domain.ext/categories/books/programming > domain.ext/categories/programming/ > domain.ext/categories/software/ > domain.ext/categories/software/product/ > domain.ext/categories/software/product/downloads > domain.ext/categories/software/product/reviews this shouldn't be a problem. you just need to split the args in the categories index () function. You then build you complexity in there, perhaps limiting your depth to 4 /cat/subcat/subsubcat/id ? have a look at the display method of the PagesController (in cakephp core), as this is built to handle a 2 level structure, it shouldn't be much hassle to extend it (a pseduo version below): function index() { $arrCats = func_get_args(); // main cat $category = $arrCats[0]; if (!empty($arrCats[1])) { $subCategory = $arrCats[1]; } } Also, if done correctly, I see no reason why you should need to use custom SQL, find and findall should be more than adequate provided your associations have been set correctly. hth jon -- jon bennett t: +44 (0) 1225 341 039 w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Nested categories controller and routing
I have thought of all of this before and none of these solutions quite seems to solve my problem. I need to be able to recover the id for the category entry in order to reference various related models to generate the content. The number of parameters in the url needs to be dynamic and must control a mysql self join. The results of this self join need to populate the category model. I can not pass the id into the controller in this case. I also can't use a findall or findallbyname since the names of a category might not be unique. I need to be able to handle an url like the following examples. All of them. domain.ext/categories/books/ domain.ext/categories/books/programming domain.ext/categories/programming/ domain.ext/categories/software/ domain.ext/categories/software/product/ domain.ext/categories/software/product/downloads domain.ext/categories/software/product/reviews where the parameters passed to the categories controller will determine what else happens. I can control the rest but I can't seem to get around populating the category model with the information it needs. I can get the param count and construct the query manually - is there a trick to approaching this problem from such an angle? Am I missing something entirely. I cant split the controllers up. I need this to work from a single categories_controller and I need to get the id of the category from the nested url in a single query if at all possible. A self join will do this. I can manage the sql generation easily enough. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Nested categories controller and routing
hi -routes are like Controller/Action/Param/Param -the 'index' is the default action Take your 'Categories' structure and name it articles, so that the route will be domain.ext/ then use the index() method. feed it with you article name's and convert them to id to do your article management. Something like that: class ArticlesController extends AppController{ function index($name=null){ $row = $this->findAllByName($name); $id = $row['id']; //then get your article content } } you'll need to convert your id to names for your links by using findAllById($id). You need also to make sure that your article names are uniques and that your are using an appropriate way to pass special characters in the url. HTH olivvv gremlin wrote: > If I create a model with a relationship to itself ie a nested > categories model with a belongs to and has many relationship I can > easily enough get a set of nested categories data. > > The problem for me is that if I wish to reference the content related > to that category I must either reference it directly or set a nesting > depth limit on the parameters I pass via the url. More clearly I can't > figure out how I could set a controller to read category information > from an url that might have no parameters or 5 or 13 or any other > number. > > Is there a way to take a structure like so : > Categories > __ > id - parent_id - value > __ > 0 - null- null > 1 - 0- articles > 2 - 0- files > 3 - 1- programming > 4 - 3- php > > etc.. > > and represent the actual hierarchy in the url as parameters? > domain.ext/ > domain.ext/articles > domain.ext/articles/php > > particulary in the case where in the future I might want to add a > sub-category to "php" thus making the url into > domain.ext/articles/php/cake or similiar? > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Nested categories controller and routing
> More clearly I can't > figure out how I could set a controller to read category information > from an url that might have no parameters or 5 or 13 or any other > number. The pages controller has these two methods in them: if (!func_num_args()) { $this->redirect('/'); } $path=func_get_args(); Is that the functionality you were after? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Nested categories controller and routing
On 10/31/06, Eric C Blount <[EMAIL PROTECTED]> wrote: A really quick search of the group for "routing" came up with many examples, but all you need to do is put something like the following in your /app/config/routes.php:$Route->connect('/articles/:param1', array('controller' => 'yourController', 'action' => 'yourAction')); $Route->connect('/articles/:param1/:param2', array('controller' => 'yourController', 'action' => 'yourAction'));Then you can access the data with $this->params['param1'] and $this->params['param2']. EricHi guys,Just wondering. Wouldn't using routes mean adding a route for every combination of params you want to use?Have you looked at the 'Nested Set' model in cakeforge? Sonic --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Nested categories controller and routing
A really quick search of the group for "routing" came up with many examples, but all you need to do is put something like the following in your /app/config/routes.php:$Route->connect('/articles/:param1', array('controller' => 'yourController', 'action' => 'yourAction')); $Route->connect('/articles/:param1/:param2', array('controller' => 'yourController', 'action' => 'yourAction'));Then you can access the data with $this->params['param1'] and $this->params['param2']. EricOn 10/31/06, gremlin <[EMAIL PROTECTED]> wrote:> > If I create a model with a relationship to itself ie a nested> categories model with a belongs to and has many relationship I can > easily enough get a set of nested categories data.> > The problem for me is that if I wish to reference the content related> to that category I must either reference it directly or set a nesting > depth limit on the parameters I pass via the url. More clearly I can't> figure out how I could set a controller to read category information> from an url that might have no parameters or 5 or 13 or any other > number.> > Is there a way to take a structure like so :> Categories> __> id - parent_id - value> __> 0 - null- null > 1 - 0- articles> 2 - 0- files> 3 - 1- programming> 4 - 3- php> > etc..> > and represent the actual hierarchy in the url as parameters? > domain.ext/> domain.ext/articles> domain.ext/articles/php> > particulary in the case where in the future I might want to add a> sub-category to "php" thus making the url into > domain.ext/articles/php/cake or similiar?> > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---