Codeigniter url 路径

发布于 2024-11-17 21:00:10 字数 425 浏览 3 评论 0原文

这是我提出这个问题的最简单的方法,因为我还没有完全理解发生了什么,或者我做错了什么。

我的网址有问题。

http://localhost/index.php/user 相同 http://localhost/ 但是 http://localhost/index.php/user/something 不同 http://localhost/something

我该如何制作http://localhost/something 工作吗?

它是否必须是 http://localhost/user/something ,我该如何使其工作?

This is the most simple way I can ask this question as I have not fully understood what's going on, or what I am not doing right.

I'm having trouble with the url.

http://localhost/index.php/user is the same as http://localhost/
but
http://localhost/index.php/user/something is not the same as http://localhost/something

How do I make http://localhost/something work?

Does it have to be http://localhost/user/something, how do I make that work?

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

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

发布评论

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

评论(4

泪是无色的血 2024-11-24 21:00:10

您需要了解 CodeIgniter 的 URL 是如何工作的。

  • URL 由一些段组成。 http://localhost/index.php/user/something/thing 在此示例中,usersomethingthing > 是 URL 的片段。

  • URL 的各个部分指示将运行哪个控制器以及该控制器的哪个方法。 http://localhost/index.php/user/something/thing 在此示例中,调用 user 控制器中的 something 方法,并且 thing 作为参数传递给该方法。

  • URL 的第一段表示控制器。

  • URL 的第二段指示该控制器的方法。

  • 以下段作为参数发送到该方法。

但有一些默认值。

  • 如果您的 URL 是 http://localhost/index.php/something,则您已将 something 指定为控制器,但因为您没有指定任何方法,调用默认方法index。所以上面的 URL 与 http://localhost/index.php/something/index

    相同

  • 如果你的 URL 是 http://localhost/index.php/ code>,您没有指定任何段(没有控制器,也没有方法)。因此,在 application\config\routes.php 中指定的默认控制器是加载的控制器。将调用该控制器的哪个方法?当然是 index 方法。

    --您可以通过将 $route['default_controller'] = "site"; 更改为 application\config\routes.php< 中适合您的应用程序的内容来设置默认控制器/code> 的文件。

  • 如果您希望 http://localhost/user/somethinghttp://localhost/index.php/user/something 相同,那么您有为您的应用程序创建自定义路由。有关该内容的更多信息此处

You need to understand how CodeIgniter's URLs work.

  • An URL consists of some segments. http://localhost/index.php/user/something/thing In this example user, something and thing are segments of the URL.

  • Segments of the URL indicate which controller and which method of that controller will run. http://localhost/index.php/user/something/thing In this example the method something from user controller is called and thing is passed to that method as a parameter.

  • The first segment of the URL indicates the controller.

  • The second segment of the URL indicates the method of that controller.

  • The following segments are sent to that method as parameters.

But there are some defaults.

  • If your URL is http://localhost/index.php/something, you have something specified as the controller, but because you have not specified any method, the default method which is index is called. So the above URL is the same as http://localhost/index.php/something/index

  • If your URL is http://localhost/index.php/, you don't have any segments specified (no controller and no method). So the default controller which is specified in application\config\routes.php is the loaded controller. Which method of that controller will be called? Of course the index method.

    --You can set the default controller by changing $route['default_controller'] = "site"; to what ever fits your application in application\config\routes.php's file.

  • If you want http://localhost/user/something to be the same as http://localhost/index.php/user/something, you have to create custom routes for your application. More info on that here.

尬尬 2024-11-24 21:00:10

http://localhost/something 表示您正在调用 Something 控制器类的索引方法

http://localhost/user/something 表示您正在调用 User 控制器类中的 some 方法。

这有道理吗?

http://localhost/something indicates that you are calling the index method of the Something controller class

http://localhost/user/something indicates that you are calling the something method in the User controller class.

Does that make sense?

踏月而来 2024-11-24 21:00:10

为了使 http://localhost/something 工作,您需要一个名为 something 且具有 index 方法的控制器。这与访问 http://localhost/something/index 相同。

或者,http://localhost/user/something 暗示您有一个 user 控制器,其方法名为 something

这有帮助吗?

In order to make http://localhost/something work, you need a controller called something with an index method. This would be the same as accessing http://localhost/something/index.

Alternatively, http://localhost/user/something implies that you have a user controller with a method called something.

Does that help at all?

柠栀 2024-11-24 21:00:10

要从 URL 中删除 index.php,您必须使用 此处 描述的 mod_rewrite 方法,

然后删除控制器网址中的名称(用户),您需要使用 routes

在您的情况下,您将添加$route['^(something|something_else|etc)(/:any)?$'] = "user/$0"; 到你的routes.php 文件

To remove index.php from your URL you have to use the mod_rewrite method described here

Then to remove the controller name (user) from the url, you need to use routes

In your case, you would add $route['^(something|something_else|etc)(/:any)?$'] = "user/$0"; to your routes.php file

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