2016-01-09 22 views
1

我无法找到解决方案,如果我的问题是重复的,请提供参考链接。所以我需要你的帮助。 这里有一个例子:如何将GET方法表单的url更改为codeigniter中的斜杠3

本地主机/ CI/index.php文件/搜索/歌曲=希拉+上+ 7

本地主机/ CI/index.php文件/搜索/ sheila_on_7

本地主机/ CI/index.php文件/搜索/曲/ sheila_on_7

感谢。

+0

感谢..我现在 –

回答

1

CodeIgniter可以选择支持这个功能,它可以在application/config.php文件中启用。如果你打开你的配置文件,你会看到这些项目:

$config['enable_query_strings'] = FALSE; 
$config['controller_trigger'] = 'c'; 
$config['function_trigger'] = 'm'; 

如果将“enable_query_strings”更改为TRUE,则此功能将变为活动状态。

index.php?c=controller&m=method 

更多信息可以在CodeIgniter URLs用户可以找到指导

+0

我试过..但没有工作.. –

0

你必须改变:那么你的控制器和功能将通过使用已设置调用你的控制器和方法的“触发”的话可以访问从GET到POST的形式方法。您可以使用Inflector helper函数,也可以使用PHP函数str_replace()。不是这样的:

<?php defined('BASEPATH') OR exit('Not your cup of tea'); 

class Search extends CI_Controller 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->load->helper('inflector'); 
    } 

    public function song($song) 
    { 
     $song = underscore($this->input->post('song'));//name of field in view which becomes sheila_on_7 

     //use variable for DB search or what ever you need 

     //$data['song'] = $this->Song_m->get('title', $this->input->post('song')); 

     //$this->load->view('search', $data); 

    } 
} 
+0

我需要使用get方法在我的网站,因为我想要显示它在搜索引擎上,像(http:** mysite.com/search/what_do_you_mean)。但是现在我已经找到了另一种方式,我仍然使用(http:** mysite.com/search/?query=keyword),因为在我使用'?query = keyword'之前,我得到了404,并且在将uri_protocol替换为auto进展顺利。谢谢你的方式 –

+0

Np。快乐的编码。 ;) – Tpojka

+0

快乐编码:D(y) –

相关问题