> Just wondering how to go about setting up Products with the tree behaviour.
> I have all my products added, categories / sub categories and so on. So how
> would I get a URL to be site/products/shoes/mens/nike/27 based on the tree?
> Rather than products/27
>
> Just looking for some good insight, tutorials where i can learn more.
One option would be to have a method that accepts an arbitrary number
of params, at the top of your method use func_get_args() to get them
all. If the last one is an int, show the product, otherwise grab the
category using the slug.
// Route:
Router::connect('/site/*', array('controller' => 'products', 'action'
=> 'view'));
public function view() {
$args = func_get_args();
// last arg is an int, must be a product id
if (is_int($args[count($args)-1])) {
$id = Sanitize::paranoid($args[count($args)-1]);
$this->data = $this->Product->find('first', array(
'conditions'=>array('Product.id'=>$id)
));
// else it's a string, grab the category
} else {
$handle = Sanitize::paranoid($args[count($args)-1], array(' ', '.',
'+', '_', '-'));
$this->data = $this->Product->ProductCategory->find('first', array(
'conditions'=>array('ProductCategory.handle'=>$handle)
));
}
}
hth
Jon
--
jon bennett - www.jben.net - blog.jben.net
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment