CodeIgniter URL 帮助

发布于 2024-09-19 01:42:55 字数 348 浏览 3 评论 0原文

我计划在 CodeIgniter 中重新创建我的歌词网站。 目前,我的设置方式是这样的:
example.com/artistnameexample.com/anotherartist

我还有 example.com/contactexample.com/request< /code> 等等。

我可以将其设置为 example.com/artist/artistname,但我真的希望保持简单,以便用户记住网址。

谁能帮我解决这个问题吗?

谢谢, 麦克尔

I'm planning on re-creating my lyrics website in CodeIgniter.
At the moment, the way I have it set-up is like this:
example.com/artistname and example.com/anotherartist

I also have example.com/contact and example.com/request etc..

I can get it to be example.com/artist/artistname, but I'd really like to keep it simple for the user to memorize the urls.

Can anyone help me out with this?

Thanks,
Maikel

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

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

发布评论

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

评论(2

ま昔日黯然 2024-09-26 01:42:56

application/config/routes.php 中尝试:

$route['contact'] = 'contact'; // /contact to contact controller
$route['request'] = 'request'; // /request to request controller
$route['(.*)'] = 'artist/display/$1'; // anything to artist controller, display method with the string as parameter

In application/config/routes.php try:

$route['contact'] = 'contact'; // /contact to contact controller
$route['request'] = 'request'; // /request to request controller
$route['(.*)'] = 'artist/display/$1'; // anything to artist controller, display method with the string as parameter
双手揣兜 2024-09-26 01:42:56

通过此处的 CodeIgniter 用户指南: http://codeigniter.com/user_guide/general/routing.html

您可以将任何内容 (:any) 重新映射到您的 artist 控制器。从那里,您可以将 contactrequest 等重新映射到各自的控制器/函数,或者您可以使用构造函数来检查这些并调用正确的函数。示例:

使用 URI 路由:

$route['contact'] = "contact";
$route['request'] = "request";
... // etc...
$route['(:any)'] = "artist/lookup/$1"; // MUST be last, or contact and request will be routed as artists.

使用构造函数:

public function __construct($uri) {
    if ($uri == "contact") {
        redirect('contact');
    } elseif ($uri == "request") {
        redirect('request');
    }
}

但是,此方法可能会导致无限循环。我不建议这样做,除非您的 contactrequest 功能位于同一个控制器中。然后您可以使用 $this->contact()$this->request() 来调用它们,而不是重定向。

Via the CodeIgniter User Guide here: http://codeigniter.com/user_guide/general/routing.html

You can remap anything (:any) to your artist controller. From there, you can remap contact, request, etc. to their respective controllers/functions or you can use your Constructor to check for those and call the correct function. Examples:

Using URI Routing:

$route['contact'] = "contact";
$route['request'] = "request";
... // etc...
$route['(:any)'] = "artist/lookup/$1"; // MUST be last, or contact and request will be routed as artists.

Using your Constructor:

public function __construct($uri) {
    if ($uri == "contact") {
        redirect('contact');
    } elseif ($uri == "request") {
        redirect('request');
    }
}

This method, however, could result in an infinite loop. I would not suggest it, unless your contact and request functions were in the same controller. Then you could just call them with $this->contact() or $this->request() instead of the redirect.

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