带 slug 和语言的 CakePHP 路由器

发布于 2024-12-29 13:26:12 字数 883 浏览 1 评论 0原文

我试图在 CakePHP 中管理我的路线,但有点陷入困境。我阅读了 www 上的几乎每一篇文章,其中一些文章接近我需要的内容,但与其他文章结合起来却无法按预期工作。还尝试了一些路由器 lib-s,但相同

这就是我需要的:

url 中的语言参数和页面的 slug。所以:

前端

目录“/”应该指向默认语言,controller => pages , slug =>; 首页

/:lang - 与上面相同,但使用选定的语言

/:slug - 控制器 => 页面操作 => index 并传递 :slug 参数,使用默认语言

/:lang/:slug - 与上面设置的 lang 参数相同

/:控制器/:slug -

/:lang/:controller/:slug - 与上面设置的 lang 参数相同

  • 我不需要这些链接中的任何操作-s

管理面板

/admin - '控制器' => '设置', '操作' => '索引'

/admin/:controller/:action/ ....这是默认的

  • 管理网址中不需要语言参数,但操作存在,索引操作除外

另外我应该如何在视图内创建链接,以便路由器正常工作?

I am a bit in dead end trying to mane my routes in CakePHP. I read almost every article in the www and some of them close to what i need but combining with other dont work as expected. Also tried some router lib-s, but the same

Here is what I need:

Both language parameter in the url and a slug of the pages. So:

for the frontend

the directory '/' should lead to the default language, controller => pages , slug => home

/:lang - the same as above but with selected language

/:slug - controller => pages , action => index and to pass the :slug parameter, with default language

/:lang/:slug - the same as above with set lang parameter

/:controller/:slug -

/:lang/:controller/:slug - the same as above with set lang parameter

  • I dont need any action-s in those links

for the admin panel

/admin - 'controller' => 'settings', 'action' => 'index'

/admin/:controller/:action/ .... this one is the default

  • no need for language parameter in the admin url, but actions exists, except the index action

Also how should I create the links inside the view, so the routers to be working as the should?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尐籹人 2025-01-05 13:26:12
    Router::connect("/admin", array('action' => 'index', 'controller' => 'settings', 'prefix' => 'admin', 'admin' => true));
    Router::connect("/admin/:controller", array('action' => 'index', 'prefix' => 'admin', 'admin' => true));
    Router::connect("/admin/:controller/:action/*", array('prefix' => 'admin', 'admin' => true));

    Router::connect("/:language/*", array('action' => 'home', 'controller' => 'pages'));
    Router::connect("/:language/:controller", array('action' => 'index'));
    Router::connect("/:language/:controller/*");

您可以复制第二组路由,但将 :language 更改为 slug,您应该将其放在 if 中并验证给定的语言,如果未验证则加载 slug 路由。

    Router::connect("/admin", array('action' => 'index', 'controller' => 'settings', 'prefix' => 'admin', 'admin' => true));
    Router::connect("/admin/:controller", array('action' => 'index', 'prefix' => 'admin', 'admin' => true));
    Router::connect("/admin/:controller/:action/*", array('prefix' => 'admin', 'admin' => true));

    Router::connect("/:language/*", array('action' => 'home', 'controller' => 'pages'));
    Router::connect("/:language/:controller", array('action' => 'index'));
    Router::connect("/:language/:controller/*");

You can copy past the second set of routes, but changing :language to slug, you should put it in an if and validate the language given, if it doesn't validate then load the slug routes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文