CakePHP:每个团队的URL前缀

时间:2014-10-12 17:28:09

标签: php cakephp cakephp-3.0

我正在开发一个CakePHP 3网站。我想根据团队展示内容。在每个控制器中,我想访问当前的团队。

E.g:

  

www.url.com/team1 - > Team = team1,Controller = Home,Action = Index

     

www.url.com/team2 - > Team = team2,Controller = Home,Action = Index

     

www.url.com/team3 - > Team = team3,Controller = Home,Action = Index

     

...

我想为所有团队使用相同的控制器,但所显示的内容基于团队。什么是最好的完成这个?路由似乎不适合我,我玩了一下。

2 个答案:

答案 0 :(得分:1)

// HomeController.php
public function index($team = null) {
    echo 'Hello Team ' . $team;
}

// routes.php
Router::connect(
    '/team:id', 
    ['controller' => 'Home', 'action' => 'Index'],
    ['id' => '[0-9]+']
);

Reference

答案 1 :(得分:0)

只需使用 routes.php :)

在routes.php中:

Router::connect('/team/*', array('controller'=>'Home', 'action'=>'index'));
In products_controller.php:

在Controller.php中

function index($id = null) {
    echo "Team" . $id;
}

http://book.cakephp.org/2.0/en/development/routing.html