Php 将变量传递给codeigniter中的默认控制器
我在codeigniter中有一个默认控制器Php 将变量传递给codeigniter中的默认控制器,php,codeigniter,Php,Codeigniter,我在codeigniter中有一个默认控制器 class Welcome extends CI_Controller { public function index() { $this->load->view('welcome_message'); } 如你所知,我们可以调用这个函数 sitename/index.php 或 因为我在.htaccess中重写了url 现在我想调用相同的索引函数,参数传递如下 sitename/seo-se
class Welcome extends CI_Controller {
public function index()
{
$this->load->view('welcome_message');
}
如你所知,我们可以调用这个函数
sitename/index.php
或
因为我在.htaccess中重写了url
现在我想调用相同的索引函数,参数传递如下
sitename/seo-services
其中seo服务将被传递到索引函数以加载seo服务页面
codeigniter的默认语法是
example.com/class/function/ID
我想要这个表格
example.com/class/ID
我想跳过类的默认(索引)函数的函数
我该怎么做
谢谢
正如你所看到的,我是为了搜索引擎优化而尝试的。附加到url的参数会自动转换为方法的参数 例如,如果在欢迎控制器中有一个名为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,则通过.htaccess;如果使用iis,则通过web.config)附加到url的参数将自动转换为方法的参数 例如,如果在欢迎控制器中有一个名为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,则通过.htaccess;如果使用iis,则通过web.config)亲爱的,我也这么做了,但我发现错误404页面未找到,实际上,我正在尝试将值传递给默认控制器,我的url类似于代码下面段落中提到的localhost/seo服务。您首先需要设置.htaccess(如本文所述)。然后,你需要修改你的应用程序/config/routes.php中的路由(如这里的文档所解释的)我想我无法解释你,看默认语法是example.com/class/function/ID我想要example.com/class/ID,我将跳过classindex函数的函数亲爱的谢谢你的及时回复,你能给我一个路线的例子吗?亲爱的谢谢你的及时回复,你能给我一个路线的例子吗?事实上,我有以下路线,但它不工作$route['(:any)]='welcome/$1';亲爱的,我也这么做了,但我得到了错误404页未找到,实际上我正在尝试将值传递给默认控制器,我的url就像下面代码段落中提到的localhost/seo服务。您首先需要设置.htaccess(如本文所述)。然后,你需要修改你的应用程序/config/routes.php中的路由(如这里的文档所解释的)我想我无法解释你,看默认语法是example.com/class/function/ID我想要example.com/class/ID,我将跳过classindex函数的函数亲爱的谢谢你的及时回复,你能给我一个路线的例子吗?亲爱的谢谢你的及时回复,你能给我一个路线的例子吗?事实上,我有以下路线,但它不工作$route['(:any)]='welcome/$1';