例如,我的URL及其相应的操作,将类似于:
(A)对于company_id属于公司=百事的用户
/pepsi/ - controller - users, action - dashboard (their Auth->user 'company_id' will be used and their user->id)
/pepsi/companies/view - controller - companies, action - view
/pepsi/users/ - controller - users, action - index (trailing slash preferably optional)
/pepsi/users/dashboard - controller - users, action - dashboard( 1) b:对于company_id属于公司=可口可乐的用户
/coke/ - controller - users, action - dashboard
/coke/companies/view - controller - companies, action - view
/coke/users/ - controller - users, action - index (trailing slash preferably optional)
/coke/users/dashboard - controller - users, action - dashboard2)对于管理员,它使用路由前缀adminperson
/adminperson/users - controller - users, action - index
/adminperson/users/view/3 - controller - users, action - view , id = 3
/adminperson/companies/delete/6 - controller - companies, action - delete Id = 63)同样重要的是,当用户未登录时,也有公共页面。/ contents / view /3 -控制器-内容、操作视图和id =3
下面是我到目前为止所得到的最好的结果,但它总是要求将动作索引显式地写入URL --但实际上,我想这并不是Html->链接助手应该产生的问题。我很高兴与助手建立我所有的联系,因为我通常这样做。
最佳尝试:
Router::connect('/:companyslug/:controller/:action', array('controller' => 'companies', 'action'=>'index', 'companyslug'=>'test'));发布于 2011-10-12 17:52:48
我有一个类似的设置,除了我正在跟踪路径的第一部分,以确定哪些记录显示。这是我的设置,其中":app“代替了您所称的":companyslug":
$app_names = "app1|app2|test_app"; // In real code these are pulled from a model
Router::connect(
'/:app/:controller/:action/*',
array( ),
array(
'persist'=>array('app'),
'app'=>$app_names
)
);
Router::connect(
'/:app/:controller',
array('action'=>'index'),
array(
'persist'=>array('app'),
'app'=>$app_names
)
);
Router::connect(
'/:app',
array('controller'=> 'pages', 'action'=>'display', 'home'),
array(
'persist'=>array('app'),
'app'=>$app_names
)
);
// Allow non-app specific access. (I have disabled the default CakePHP routes.)
Router::connect('/:controller', array('action' => 'index'));
Router::connect('/:controller/:action/*');注意:这是来自Cake2.0RC3,但我认为它应该在1.3中同样工作。
通过这种方式,您可以在控制器中检索app的值(在request参数下),并确保它们在正确的URL中(在您的情况下,确保company_id = companyslug )。
一个棘手的问题是“持久化”选项,这意味着您总是需要使用Helper的链接函数来维护URL中的正确前缀。
发布于 2011-10-12 13:19:07
你可以在路线上使用Regex,比如-
Router::connect('/:companyslug/:controller/:action', array('controller' => 'companies', 'action'=>'index'), array('companyslug'=>'[A-Za-z0-9_\-]*'));https://stackoverflow.com/questions/7738211
复制相似问题