2016-01-09 25 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) –

相關問題