无法通过uri段Codeigniter 3.0获取get变量


Cannot get GET variable by uri segment Codeigniter 3.0

我有以下url,

localhost/socialmedia/post/?search=andy

我想得到"搜索变量"

但是我得到了这个错误,

Unable to determine what should be displayed. A default route has not been specified in the routing file.

在路由文件中似乎有需要设置的内容

我该怎么办?

*信息我一直在检查Codeigniter 3.0 Url文档,但没有进一步的解释。https://www.codeigniter.com/userguide3/general/urls.html

任何答复都将不胜感激。

config.php

更改此项:

 $config['enable_query_strings'] = FALSE;

至:

$config['enable_query_strings'] = TRUE;

但请记住:

启用查询字符串

默认情况下,CodeIgniter使用搜索引擎友好的基于分段的URL:example.com/who/what/where/

默认情况下,CodeIgniter允许访问$_GET数组。如果有的话若要禁用它,请将"allow_get_array"设置为FALSE。

您可以选择启用基于标准查询字符串的URL:example.com?谁=我&what=something&其中=此处

选项为:TRUE或FALSE(布尔值)

其他项允许您设置查询字符串"words"调用控制器及其功能:example.com/index.php?c=控制器&m=功能

请注意,当由于CodeIgniter主要用于使用基于分段的URL。

启用后

$config['enable_query_strings'] = TRUE;

例如,你的url需要是

http://localhost/socialmedia/?c=post&search=andy

Config.php

更改此

$config['uri_protocol'] = 'REQUEST_URI';

$config['uri_protocol'] = 'QUERY_STRING';

然后如何使用下面的链接。

$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';

以及在使用url助手时

site_url('c=post&search=1234');
application 
application > controllers >
application > controllers > Post.php

如果在子目录中

site_url('d=some_folder&c=post&search=1234');
application 
application > controllers >
application > controllers > some_folder >
application > controllers > some_folder > Post.php

它会自动拾取吗?d 之前

不过,您可能需要配置uri路由。

http://www.codeigniter.com/user_guide/general/routing.html