如何根据 URI 查找 Code Igniter 中正在使用的视图

How to find what view is being used in Code Igniter based on the URI

我是 Codeigniter 的新手,我刚刚继承了一个网站,其中的视图、控制器和模型的命名与 URI 不一致。例如:mysite.com/about-us 在 vi​​ews 文件夹中可能被称为 our-bio.php.

config/routes.php 似乎没有自定义,所以我不确定他的页面的 slug 是从哪里来的。

我如何根据页面的 URI 知道要编辑什么?

例如

- application
  - controllers
    - About_us.php
  - config
    - routes.php

default controller只在没有URL段时使用。它只调用一个方法,一个controller的默认方法是index().

  • 根据uri你可以找到正在使用的controllermethod,只要没有路由,如果路由你将不得不看到routes.php 或您的 .htaccess 文件
  • 一旦知道调用了哪个方法,就可以看到加载了哪个视图,即来自$this->load->view('view_file',....,....)

通常,您的 URL 的第一部分映射到控制器:

这将调用联系人控制器的索引方法:

http://yoursite.com/about_us
                      ^
                    controller

这将调用 about_us 控制器的 what_we_do 方法:

http://yoursite.com/about_us/what_we_do
                     ^           ^
                  controller    method

这将调用 about_us controllerwhat_we_do method 并将 india 作为第一个参数传递:

 http://yoursite.com/about_us/what_we_do/india

Read all about it in the user guide

Routing