在编码器中将变量传递给默认控制器


passing variable to default controller in codeigniter

我在codeigniter中有一个默认控制器

class Welcome extends CI_Controller {
    public function index()
    {
        $this->load->view('welcome_message');
    }

我们可以调用这个函数

sitename/index.php

sitename/

,因为我把url重写为。htaccess

现在我想调用相同的索引函数,参数传递像

sitename/seo-services

,其中seo-services将作为参数传递给索引函数,以加载seo-services页面。

作为codeigniter的默认语法是

example.com/class/function/ID

我想在这个格式

example.com/class/ID

,我想跳过函数的默认(索引)函数类

我该怎么做?

感谢

正如你所看到的,我正在尝试这个seo的目的。

附加在url后面的参数会自动转换为方法的参数。

例如,如果您在欢迎控制器中有一个名为index index的方法,那么http://www.example.com/index.php/welcome/index/[parametervalue]将自动将[parametervalue]传递给您的方法,假设您定义了接收参数

的函数
class Welcome extends CI_Controller {
    public function index($parameterValue=null)
    {
      //do whatever you need here
      //note the default value just in case it is null
    }
}

如果你想让事情变得更短,你必须在config/routes.php文件中定义一个别名。此外,如果您想摆脱index.php,您将不得不相应地配置您的web服务器(如果使用apache或web. php,可以通过.htaccess)。如果使用iis,请配置