我正在使用CakePHP 2.5.x,并且使用默认路由正常工作。现在,我想前缀会根据用户登录公司名称参数。在CakePHP中将公司名称前缀为URL
举例来说,目前是这样工作的
http://localhost/Pages/view
http://localhost/Pages/add
我想它的工作这样
http://localhost/acme/Pages/view
http://localhost/acme/Pages/add
我已经配置routes.php文件的配置文件来照顾实际路由的上面以下行
/**
* Catch urls like http://www.domain.com/<company>/<controller>/<action>/<parameters>
*/
Router::connect(
'/:company/:controller/:action/*',
array(),
array (
'company' => '[a-zA-Z0-9]+' // regular expression match for the company parameter
)
);
/**
* Catch urls like http://www.domain.com/<company>/<controller>/<action>
*/
Router::connect(
'/:company/:controller/:action',
array(),
array (
'company' => '[a-zA-Z0-9]+' // regular expression match for the company parameter
)
);
/**
* Catch urls like http://www.domain.com/<company>/<controller>/
*/
Router::connect(
'/:company/:controller',
array (
'action' => 'index'
),
array (
'company' => '[a-zA-Z0-9]+' // regular expression match for the company parameter
)
);
/**
* Catch urls like http://www.domain.com/<company>/
*/
Router::connect(
'/:company',
array(
'controller' => 'Users', // default controller
'action' => 'index' // default action
),
array (
'company' => '[a-zA-Z0-9]+' // regular expression match for the company parameter
)
);
我遇到的问题是,在我的应用程序的很多地方我已经使用echo Router::url('')
,现在所有这些链接都需要更新。是否有一些通用的方法可以确保用户登录后,为该用户生成的所有链接都将获得相关的公司名称和前缀?
帮助表示赞赏。
去core.php中并添加以下行配置::写入( 'Routing.prefixes',阵列( 'ACME')); –
去你的控制器,并添加公共功能pages_dashboard(){} –
等功能,并查看名称应该是pages_dashboard –