Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将值/变量直接传递给codeigniter中的默认控制器?_Php_Codeigniter - Fatal编程技术网

Php 如何将值/变量直接传递给codeigniter中的默认控制器?

Php 如何将值/变量直接传递给codeigniter中的默认控制器?,php,codeigniter,Php,Codeigniter,假设基本url为“” 默认控制器为“主” 如何对路由和控制器进行编码以将URL设置为“” 其中“noddycha”是一个get参数。页面应该从DB加载我的个人资料页面。在应用程序/routes.php文件中,在$route['404\u override']=''之后添加这一行: $route['(:any)'] = 'users/profile'; 现在,所有内容都将被重定向到用户控制器的配置文件函数(或您在routes.php文件中替换的任何控制器/函数组合)。然后,您可以在profile

假设基本url为“”

默认控制器为“主”

如何对路由和控制器进行编码以将URL设置为“”


其中“noddycha”是一个get参数。页面应该从DB加载我的个人资料页面。

在应用程序/routes.php文件中,在
$route['404\u override']=''之后添加这一行

$route['(:any)'] = 'users/profile';
现在,所有内容都将被重定向到
用户
控制器的
配置文件
函数(或您在routes.php文件中替换的任何控制器/函数组合)。然后,您可以在
profile
函数中执行此操作来获取参数:

if ($this->uri->total_segments() === 1) {
    $profile = $this->uri->total_segment(1);
}
如果您还有其他一些控制器,您仍然希望能够访问这些控制器,例如“关于我们”页面,请将它们添加到routes.php文件的上一行之后。例如,如果我们扩展上述示例:

$route['(:any)'] = 'users/profile';
$route['home/about'] = 'home/about_us';

这意味着除了
http://example.com/home/about
将转到关于我们的页面。

假设主控制器有默认的
index()
方法,让它接受$user\u配置文件的参数。可能的重复项