Re: Routing to 2 controllers?

2014-12-22 Thread . .
I think that is the answer I am looking for. I just need to re-arrange my
methods then. Thanks for clarifying.

On Sun, Dec 21, 2014 at 7:38 PM, Andrew Lechowicz drew.lechow...@gmail.com
wrote:

 Ok. Here's a Gist of what your code might look like:
 https://gist.github.com/alecho/e7b573cc54140ba1706d

 By making the methods private it means that CakePHP won't let them be
 publicly callable methods. This avoids redirects so that your url is still
 the same too. I think this approach is easier to test as well.

 This assumes that you can't just use regular expressions on the username
 to route to different controllers or actions. In other words, your username
 has nothing to do with wether your user is a user or a shop. You may
 also want to look into ensuring usernames are valid in the router with a
 custom route class but this is not required. Check out Mark Story's post on
 this:
 http://mark-story.com/posts/view/using-custom-route-classes-in-cakephp.

 On Sunday, December 21, 2014 5:56:18 AM UTC-5, . . wrote:

 Thanks for clarifying regarding routes.

 Could you clarify what you mean It be a simple `if` statement that calls
 one of two of the controllers `private` or `protected` methods which
 contain the login for wether the username is Bob or BobsShop.

 I have a UsersController and a ShopsController, the former handles the
 Bob username while the latter handles BobsShop username. So if i route
 the /:username url to my UsersController, how should I handle the logic for
 the BobsShop username?

 Thanks

  On Dec 20, 2014, at 9:09 PM, Andrew Lechowicz drew.le...@gmail.com
 wrote:
 
  Hi. I want to route a url to 2 controllers depending on some logic I
 define. For example, if I have 2 usernames Bob and BobsShop, I want
 localhost/Bob to route to my UsersController while localhost/BobsShop will
 route to my ShopsController. I've thought of one way to accomplish this -
 by writing a common ObjectsController that represents both a User and a
 Shop. Is there an easier way via cake's routing mechanism? Thanks!
 
  It seems like you might be confused as to what is a route and what is a
 controller and what is a model. A route shouldn't contain any logic, it's
 just the mapping of URL to Controller action. Or another way to put it is
 URL to logic to perform. I would suggest if you have a route like
 `/:username` it would route to a sigle controller action which then decided
 which logic to perform. It be a simple `if` statement that calls one of two
 of the controllers `private` or `protected` methods which contain the login
 for wether the username is Bob or BobsShop.
 
  --
  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 a topic in the
 Google Groups CakePHP group.
  To unsubscribe from this topic, visit https://groups.google.com/d/
 topic/cake-php/MpAJAUdAzJk/unsubscribe.
  To unsubscribe from this group and all its topics, send an email to
 cake-php+u...@googlegroups.com.
  To post to this group, send email to cake...@googlegroups.com.
  Visit this group at http://groups.google.com/group/cake-php.
  For more options, visit https://groups.google.com/d/optout.

  --
 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 a topic in the
 Google Groups CakePHP group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/cake-php/MpAJAUdAzJk/unsubscribe.
 To unsubscribe from this group and all its topics, 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.
 For more options, visit https://groups.google.com/d/optout.


-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: Routing to 2 controllers?

2014-12-21 Thread rc . gojinny
Thanks for clarifying regarding routes. 

Could you clarify what you mean It be a simple `if` statement that calls one 
of two of the controllers `private` or `protected` methods which contain the 
login for wether the username is Bob or BobsShop.

I have a UsersController and a ShopsController, the former handles the Bob 
username while the latter handles BobsShop username. So if i route the 
/:username url to my UsersController, how should I handle the logic for the 
BobsShop username? 

Thanks

 On Dec 20, 2014, at 9:09 PM, Andrew Lechowicz drew.lechow...@gmail.com 
 wrote:
 
 Hi. I want to route a url to 2 controllers depending on some logic I define. 
 For example, if I have 2 usernames Bob and BobsShop, I want localhost/Bob to 
 route to my UsersController while localhost/BobsShop will route to my 
 ShopsController. I've thought of one way to accomplish this - by writing a 
 common ObjectsController that represents both a User and a Shop. Is there an 
 easier way via cake's routing mechanism? Thanks!
 
 It seems like you might be confused as to what is a route and what is a 
 controller and what is a model. A route shouldn't contain any logic, it's 
 just the mapping of URL to Controller action. Or another way to put it is URL 
 to logic to perform. I would suggest if you have a route like `/:username` it 
 would route to a sigle controller action which then decided which logic to 
 perform. It be a simple `if` statement that calls one of two of the 
 controllers `private` or `protected` methods which contain the login for 
 wether the username is Bob or BobsShop.
 
 -- 
 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 a topic in the Google 
 Groups CakePHP group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/cake-php/MpAJAUdAzJk/unsubscribe.
 To unsubscribe from this group and all its topics, 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.
 For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: Routing to 2 controllers?

2014-12-21 Thread John Andersen
Hi

Can I assume that you have implemented authentication in your CakePHP 
application using the Auth component?
See the CakePHP book here about Authentication:
http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

Take specially a look at the section Identifying users and logging them 
in which contains a code example of the login method for your usage. As 
Andrew wrote, it should then be simple for you to implement an IF statement 
(or other) and redirect the user to the correct URL of your appilcation.

Enjoy, John


On Sunday, 21 December 2014 12:56:18 UTC+2, rc.go...@gmail.com wrote:

 Thanks for clarifying regarding routes. 

 Could you clarify what you mean It be a simple `if` statement that calls 
 one of two of the controllers `private` or `protected` methods which 
 contain the login for wether the username is Bob or BobsShop. 

 I have a UsersController and a ShopsController, the former handles the 
 Bob username while the latter handles BobsShop username. So if i route 
 the /:username url to my UsersController, how should I handle the logic for 
 the BobsShop username? 

 Thanks 

  On Dec 20, 2014, at 9:09 PM, Andrew Lechowicz drew.le...@gmail.com 
 javascript: wrote: 
  
  Hi. I want to route a url to 2 controllers depending on some logic I 
 define. For example, if I have 2 usernames Bob and BobsShop, I want 
 localhost/Bob to route to my UsersController while localhost/BobsShop will 
 route to my ShopsController. I've thought of one way to accomplish this - 
 by writing a common ObjectsController that represents both a User and a 
 Shop. Is there an easier way via cake's routing mechanism? Thanks! 
  
  It seems like you might be confused as to what is a route and what is a 
 controller and what is a model. A route shouldn't contain any logic, it's 
 just the mapping of URL to Controller action. Or another way to put it is 
 URL to logic to perform. I would suggest if you have a route like 
 `/:username` it would route to a sigle controller action which then decided 
 which logic to perform. It be a simple `if` statement that calls one of two 
 of the controllers `private` or `protected` methods which contain the login 
 for wether the username is Bob or BobsShop. 
  
  -- 
  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 a topic in the 
 Google Groups CakePHP group. 
  To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/cake-php/MpAJAUdAzJk/unsubscribe. 
  To unsubscribe from this group and all its topics, send an email to 
 cake-php+u...@googlegroups.com javascript:. 
  To post to this group, send email to cake...@googlegroups.com 
 javascript:. 
  Visit this group at http://groups.google.com/group/cake-php. 
  For more options, visit https://groups.google.com/d/optout. 


-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: Routing to 2 controllers?

2014-12-21 Thread . .
Thanks for the replies. I guess my question is still unclear, and yes, I am
using Auth. What I am trying to do is implement a URL similar to facebook.
For example, I want to have

www.xyz.com/Bob/{actions} (routes to UserController)
www.xyz.com/BobsStore/{actions} (routes to ShopsController).

I could route all the usernames to my UsersController and then use an IF to
redirect to the appropriate controller, but then I would lose the 
www.xyz.com/Username/action url syntax, right? Maybe using requestAction?

I did find an old cake thread regarding what I want to achieve. But this is
probably not recommended to do. I am not sure if there is a more elegant
way...

http://cakephp.1045679.n5.nabble.com/One-slug-route-connected-to-multiple-controllers-td5710815.html

Thanks again for any help.



On Sun, Dec 21, 2014 at 5:48 AM, John Andersen j.andersen...@gmail.com
wrote:

 Hi

 Can I assume that you have implemented authentication in your CakePHP
 application using the Auth component?
 See the CakePHP book here about Authentication:

 http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

 Take specially a look at the section Identifying users and logging them
 in which contains a code example of the login method for your usage. As
 Andrew wrote, it should then be simple for you to implement an IF statement
 (or other) and redirect the user to the correct URL of your appilcation.

 Enjoy, John


 On Sunday, 21 December 2014 12:56:18 UTC+2, rc.go...@gmail.com wrote:

 Thanks for clarifying regarding routes.

 Could you clarify what you mean It be a simple `if` statement that calls
 one of two of the controllers `private` or `protected` methods which
 contain the login for wether the username is Bob or BobsShop.

 I have a UsersController and a ShopsController, the former handles the
 Bob username while the latter handles BobsShop username. So if i route
 the /:username url to my UsersController, how should I handle the logic for
 the BobsShop username?

 Thanks

  On Dec 20, 2014, at 9:09 PM, Andrew Lechowicz drew.le...@gmail.com
 wrote:
 
  Hi. I want to route a url to 2 controllers depending on some logic I
 define. For example, if I have 2 usernames Bob and BobsShop, I want
 localhost/Bob to route to my UsersController while localhost/BobsShop will
 route to my ShopsController. I've thought of one way to accomplish this -
 by writing a common ObjectsController that represents both a User and a
 Shop. Is there an easier way via cake's routing mechanism? Thanks!
 
  It seems like you might be confused as to what is a route and what is a
 controller and what is a model. A route shouldn't contain any logic, it's
 just the mapping of URL to Controller action. Or another way to put it is
 URL to logic to perform. I would suggest if you have a route like
 `/:username` it would route to a sigle controller action which then decided
 which logic to perform. It be a simple `if` statement that calls one of two
 of the controllers `private` or `protected` methods which contain the login
 for wether the username is Bob or BobsShop.
 
  --
  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 a topic in the
 Google Groups CakePHP group.
  To unsubscribe from this topic, visit https://groups.google.com/d/
 topic/cake-php/MpAJAUdAzJk/unsubscribe.
  To unsubscribe from this group and all its topics, send an email to
 cake-php+u...@googlegroups.com.
  To post to this group, send email to cake...@googlegroups.com.
  Visit this group at http://groups.google.com/group/cake-php.
  For more options, visit https://groups.google.com/d/optout.

  --
 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 a topic in the
 Google Groups CakePHP group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/cake-php/MpAJAUdAzJk/unsubscribe.
 To unsubscribe from this group and all its topics, 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.
 For more options, visit https://groups.google.com/d/optout.


-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: Routing to 2 controllers?

2014-12-21 Thread Andrew Lechowicz
Ok. Here's a Gist of what your code might look 
like: https://gist.github.com/alecho/e7b573cc54140ba1706d

By making the methods private it means that CakePHP won't let them be 
publicly callable methods. This avoids redirects so that your url is still 
the same too. I think this approach is easier to test as well.

This assumes that you can't just use regular expressions on the username to 
route to different controllers or actions. In other words, your username 
has nothing to do with wether your user is a user or a shop. You may 
also want to look into ensuring usernames are valid in the router with a 
custom route class but this is not required. Check out Mark Story's post on 
this: http://mark-story.com/posts/view/using-custom-route-classes-in-cakephp.

On Sunday, December 21, 2014 5:56:18 AM UTC-5, . . wrote:

 Thanks for clarifying regarding routes. 

 Could you clarify what you mean It be a simple `if` statement that calls 
 one of two of the controllers `private` or `protected` methods which 
 contain the login for wether the username is Bob or BobsShop. 

 I have a UsersController and a ShopsController, the former handles the 
 Bob username while the latter handles BobsShop username. So if i route 
 the /:username url to my UsersController, how should I handle the logic for 
 the BobsShop username? 

 Thanks 

  On Dec 20, 2014, at 9:09 PM, Andrew Lechowicz drew.le...@gmail.com 
 javascript: wrote: 
  
  Hi. I want to route a url to 2 controllers depending on some logic I 
 define. For example, if I have 2 usernames Bob and BobsShop, I want 
 localhost/Bob to route to my UsersController while localhost/BobsShop will 
 route to my ShopsController. I've thought of one way to accomplish this - 
 by writing a common ObjectsController that represents both a User and a 
 Shop. Is there an easier way via cake's routing mechanism? Thanks! 
  
  It seems like you might be confused as to what is a route and what is a 
 controller and what is a model. A route shouldn't contain any logic, it's 
 just the mapping of URL to Controller action. Or another way to put it is 
 URL to logic to perform. I would suggest if you have a route like 
 `/:username` it would route to a sigle controller action which then decided 
 which logic to perform. It be a simple `if` statement that calls one of two 
 of the controllers `private` or `protected` methods which contain the login 
 for wether the username is Bob or BobsShop. 
  
  -- 
  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 a topic in the 
 Google Groups CakePHP group. 
  To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/cake-php/MpAJAUdAzJk/unsubscribe. 
  To unsubscribe from this group and all its topics, send an email to 
 cake-php+u...@googlegroups.com javascript:. 
  To post to this group, send email to cake...@googlegroups.com 
 javascript:. 
  Visit this group at http://groups.google.com/group/cake-php. 
  For more options, visit https://groups.google.com/d/optout. 


-- 
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.
For more options, visit https://groups.google.com/d/optout.


Routing to 2 controllers?

2014-12-20 Thread rc . gojinny
Hi. I want to route a url to 2 controllers depending on some logic I define. 
For example, if I have 2 usernames Bob and BobsShop, I want localhost/Bob to 
route to my UsersController while localhost/BobsShop will route to my 
ShopsController. I've thought of one way to accomplish this - by writing a 
common ObjectsController that represents both a User and a Shop. Is there an 
easier way via cake's routing mechanism? Thanks!

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Routing to 2 controllers?

2014-12-20 Thread Andrew Lechowicz
Hi. I want to route a url to 2 controllers depending on some logic I define. 
For example, if I have 2 usernames Bob and BobsShop, I want localhost/Bob to 
route to my UsersController while localhost/BobsShop will route to my 
ShopsController. I've thought of one way to accomplish this - by writing a 
common ObjectsController that represents both a User and a Shop. Is there an 
easier way via cake's routing mechanism? Thanks!

It seems like you might be confused as to what is a route and what is a 
controller and what is a model. A route shouldn't contain any logic, it's just 
the mapping of URL to Controller action. Or another way to put it is URL to 
logic to perform. I would suggest if you have a route like `/:username` it 
would route to a sigle controller action which then decided which logic to 
perform. It be a simple `if` statement that calls one of two of the controllers 
`private` or `protected` methods which contain the login for wether the 
username is Bob or BobsShop.

-- 
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.
For more options, visit https://groups.google.com/d/optout.