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

时间:2015-12-18 07:17:46

标签: php codeigniter

我有以下网址,

localhost/socialmedia/post/?search=andy

我想获得“搜索变量”

但我收到了这个错误,

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

似乎在路由文件中设置了一些内容,

我该怎么办?

* info我一直在检查Codeigniter 3.0 Url文档,但没有进一步说明。 https://www.codeigniter.com/userguide3/general/urls.html

任何给定的答案都会受到如此赞赏。

2 个答案:

答案 0 :(得分:1)

config.php

改变这个:

 $config['enable_query_strings'] = FALSE;

为:

$config['enable_query_strings'] = TRUE;

但请记住:

  

启用查询字符串

     

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

     

默认情况下,CodeIgniter可以访问$ _GET数组。如果对某些人    如果你想禁用它,请将'allow_get_array'设置为FALSE。

     

您可以选择启用基于标准查询字符串的URL:    example.com?who=me&what=something&where=here

     

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

     

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

     

请注意,部分帮助程序无法正常工作    此功能已启用,因为CodeIgniter主要是为了设计的    使用基于网段的网址。

答案 1 :(得分:0)

启用后

$config['enable_query_strings'] = TRUE;

然后例如你的网址需要

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 helper时也是如此

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