Re: Confused about routing

2013-04-17 Thread lowpass
Router::connect(
'/products/:category',
array(
'controller' => 'categories',
'action' => 'index'
),
array(
'category' => '[-a-z]+',
'pass' => array('category')
)
);

Router::connect(
'/products/:category/:product',
array(
'controller' => 'products',
'action' => 'view'
),
array(
'category' => '[-a-z0-9]+',
'product' => '[-a-z0-9]+',
'pass' => array('category', 'product')
)
);

That will work for one category level.

You may need to adjust the regex to match your slug format.


On Wed, Apr 17, 2013 at 2:45 AM, LDSign  wrote:

> Hi
>
> I am trying to make a special route, but had no success so far. Could you
> help?
>
> The url looks like:
>
> /products/:category_slug/:product_slug
>
>
> So, when "product_slug" isnt specified I would like to use
>
> array('controller' => 'categories','action' => 'index')
>
>
> and in the other case (when "product_slug" is specified):
>
> array('controller' => 'products','action' => 'index')
>
>
> For example:
>
> /products/category_a should point to /categories/index/category_a
>
>
> and (note the same category_slug)
>
> /products/category_a/product_a should point to
> /products/index/category_a/product_a
>
>
> Is this possible and could you provide an example?
>
> Thank you very much,
> Frank
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Confused about routing

2013-04-17 Thread Salines

Hi,
You need to organize a database in different way to achieve what you want.

Create the following table:

nodes - to save the name of categories or products, content types, full 
path as a slug.

id
parent_id
lft
rght
title
path
published (0,1)
type


closure - to save deep linking association. This gives you the ability to 
create an unlimited number of subcategories.

http://www.slideshare.net/billkarwin/models-for-hierarchical-data

id
ancestor
descendant

posts - to save product info
images - to save product images


Relations:

Nodes self HABTM via Closures
Nodes hasOne Post
Nodes hasMany Images
...


Routnig for example:

localhost/my-categories
localhost/my-categories/3 (pagination)
localhost/my-categories/sub-categories
localhost/my-categories/sub-categories/2  (pagination)
localhost/my-categories/sub-categories/product-name

Router::connect('/:path/*', array('admin'=>false,'controller' => 'nodes', 
'action' => 'show'),array('pass'=>array('path','page'),'page' =>'[0-9]+'));

In nodes controller:

public function show(){

$path = func_get_args();
//debug($path);
$last_arg = end(array_values($path));

if (is_numeric($last_arg)) {
$page = $last_arg;
//debug($page);
array_pop($path);
$path = implode("/", $path);
$this -> request -> params['named']['page'] = $last_arg;
} else {
$path = implode("/", $path);
}
   //debug($path);
 $check_post = $this -> Node -> find('first', array('conditions' => 
array('Node.path' => $path), 'fields' => array('Node.id', 'Node.type', 
'Node.title', ), 'recursive' => -1));
//$this -> Node -> id = $check_post['Post']['id'];
//debug($check_post);
if (!$check_post['Post']['id']) {
throw new NotFoundException(__('Invalid post'));
}
if ($check_post['Node']['type'] == 0) {
//if category , find results via paginate using joins
}
else
{
findByPath, and render product views
}

}


this would be a short explanation., maybe there is a better and simpler 
solution.

Nikola

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Confused about routing

2013-04-17 Thread Salines
Hi,
You need to organize a database in different way to achieve what you want.

Create the following table:

nodes - to save the name or category of products, content types, full path 
as a slug.

id
parent_id
lft
rght
title
path
published (0,1)
type


closure - to save deep linking association. This gives you the ability to 
create an unlimited number of subcategories.

http://www.slideshare.net/billkarwin/models-for-hierarchical-data

id
ancestor
descendant

posts - to save product info
images - to save product images


Relations:

Nodes self HABTM via Closures
Nodes hasOne Post
Nodes hasMany Images
...


Routnig for exmple:

localhost/my-categories
localhost/my-categories/sub-categories
localhost/my-categories/sub-categories/2  (pagination)
localhost/my-categories/sub-categories/product-name

Router::connect('/:path/*', array('admin'=>false,'controller' => 'nodes', 
'action' => 'show'),array('pass'=>array('path','page'),'page' =>'[0-9]+'));

In nodes controller:

public function show(){

$path = func_get_args();
//debug($path);
$last_arg = end(array_values($path));

if (is_numeric($last_arg)) {
$page = $last_arg;
//debug($page);
array_pop($path);
$path = implode("/", $path);
$this -> request -> params['named']['page'] = $last_arg;
} else {
$path = implode("/", $path);
}
   //debug($path);
 $check_post = $this -> Node -> find('first', array('conditions' => 
array('Node.path' => $path), 'fields' => array('Node.id', 'Node.type', 
'Node.title', ), 'recursive' => -1));
//$this -> Node -> id = $check_post['Post']['id'];
//debug($check_post);
if (!$check_post['Post']['id']) {
throw new NotFoundException(__('Invalid post'));
}
if ($check_post['Node']['type'] == 0) {
//if category , find results via paginate joins
}
else
{
findByPath, and render views
}

}


this would be a short explanation., maybe there is a better and simpler 
solution.

Nikola






-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.