我想在所有菜单网址中使用当前会话国家/地区名称,这仅用于在网址中显示目的
假设当前国家是北核心
当前网址为http://localhost/project-name/ products / business_verticals
我想要
网址为http://localhost/project-name/ north-corea / products / business_verticals
和north-corea仅用于显示未将其用于页面。
我在这个会话中有国家名称$ _SESSION [" csite"] ....我想将此会话值用于所有菜单网址。
答案 0 :(得分:0)
Try:
Add code on routes.php
$currentPath = Router::getPaths(true);
$currentUrl = '';
if (!empty($currentPath->query['url'])) {
$currentUrl = trim($currentPath->query['url']);
} elseif (!empty($currentPath->url)) {
$currentUrl = trim($currentPath->url);
}
if (!empty($currentUrl)) {
$currentUrlArr = explode('/', trim($currentUrl, "/"));
if ($currentUrlArr[0] == 'north-corea') {
Router::connect('/*', array('controller' => $currentUrlArr[1], 'action' => $currentUrlArr[2]));
}
}
答案 1 :(得分:0)
Cakephp本身支持它所谓的url前缀。它们被加载到routes.php配置文件中,然后可以在您的应用程序的其他地方使用。要在您的示例中构建带有前缀的URL,您可以执行
[ 'controller' => 'products', 'action' => 'business-verticals', 'north-corea' => true ]