I've got a question about best practice - it is about forcing
everything in a controller through a single method as a result of
wanting nice urls

I have a controller called Products (based on a table called products)
that also uses a table called product_items (products is actually a
table of product categories - but this is all in the name of nice
urls, product_items contains the actual products)

For example:

/products
(shows you a list of product categories e.g. 'Pet Foods')

/products/pet_foods
(shows you all the products within the 'Pet Foods' category)

/products/pet_foods/chappie
(shows you the detail page for chappie)


This all works fine - the way I have done it is to do the following, I
have set up the following route:

$Route->connect('/products/(.*)', array('controller' => 'products',
'action' => 'index'));


So anything gets pointed at the index method in the controller, my
code within the index method looks something like this:



function index($product_cat_url = null, $product_item_url = null) {


        if($product_cat_url)
                        {
                           // check the product cat is valid
                           etc.
                        }

        if($product_item_url)
                        {
                           // check the product item is valid
                          etc.
                        }

        etc.



This works great - but now I want to add locations so for instance I
might have a url like:

/products/london/pet_foods
(shows you all the products within the 'Pet Foods' category in london)




Obviously I can just add more code in the index method, but then this
in itself might get really unwieldy - but it has got me thinking is
there a better way of doing this? I was Googling and found this thread
http://groups.google.co.uk/group/cake-php/browse_thread/thread/5634c96badc17bf9/d8bc12220a9658c3b#d8bc122209658c3b
which I'd forgotten about (it was for a personal project and I've
never had to finnish it) used a beforeFilter() to pass it to a
different controller - but then I might just end up duplicating loads
of code in two methods...

So in the situations like this what do people do? Is there a better
solution?

Thanks

p.s. I'm using 1.1


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

Reply via email to