Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. <?php
  2. // Given you want to perform one of two or more actions with a single url.
  3. //
  4. // in Config/routes.php
  5.  
  6. ```
  7. Router::connect('/:username/:action', array('controller' => 'users', 'action' => 'userOrShop'));
  8. ```
  9.  
  10. ```
  11. // Your UsersController.php might look something like this then.
  12. class UsersController extends AppController {
  13.  
  14. public function userOrShop() {
  15. // Do whatever you need to do to determine if the current user is a
  16. // "shop" or just a user.
  17. if ($this->User->isShop()) {
  18. return $this->_doShopThing();
  19. }
  20.  
  21. return $this->_doUserThing();
  22. }
  23.  
  24. protected function _doShopThing() {
  25. // This is where your regular controller logic would go for when the user
  26. // is a shop like "BobsShop.
  27. }
  28.  
  29. protected function _doUserThing() {
  30. // This is where your logic for a username of "Bob" would go.
  31. }
  32. }
  33. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement