Re: Routes with optional parameters

2012-11-07 Thread lowpass
I think changing the regexp from + to ? in the first route would do it.

Router::connect(
'/open-account/:id',
array(
'controller' => 'users',
'action' => 'add'
),
array(
'pass' => array('id'),
'id' => '[a-z]?'
)
);

On Wed, Nov 7, 2012 at 11:00 AM, Jeremy Burns
 wrote:
> How do I set up a route that sometimes has a parameter and sometimes
> doesn't? For example, I have the following two routes but I'm sure they
> could be combined into one?
>
> Router::connect(
> '/open-account/:id',
> array(
> 'controller' => 'users',
> 'action' => 'add'
> ),
> array(
> 'pass' => array('id'),
> 'id' => '[a-z]+'
> )
> );
>
> Router::connect(
> '/open-account',
> array(
> 'controller' => 'users',
> 'action' => 'add'
> )
> );
>
> --
> 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 post to this group, send email to cake-php@googlegroups.com.
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>
>

-- 
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 post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Routes with optional parameters

2012-11-07 Thread Jeremy Burns
How do I set up a route that sometimes has a parameter and sometimes 
doesn't? For example, I have the following two routes but I'm sure they 
could be combined into one?

Router::connect(
'/open-account/:id',
array(
'controller' => 'users',
'action' => 'add'
),
array(
'pass' => array('id'),
'id' => '[a-z]+'
)
);

Router::connect(
'/open-account',
array(
'controller' => 'users',
'action' => 'add'
)
);

-- 
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 post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.