我不擅長php和codeigniter給了我最大的。我的網站是一個搜索引擎,我做了一個搜索後,我的網站的url是這樣的:mysite.com/?search=eminem & type = mp3我不喜歡它。 我想這樣做,所以當我鍵入搜索阿姆給我這個網址:mysite.com/eminem/mp3 下面是從CI代碼CodeIgniter和查詢字符串問題
<?php
class Pages extends CI_Controller {
public function view($page = 'home')
{
if (! file_exists('application/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
我有什麼其他的代碼在這裏補充到將qwery字符串轉換爲路徑?
這裏是routes.php文件
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
$route['404_override'] = '';
這裏是home.php我的搜索形式
<form id="searchwrapper" name="searchform"> <input type="text" class="searchbox" id="txtSearch" name="search" /> <input type="image" src="../images/empty.png" class="searchbox_submit"/>
<p id="circ">
<input type="radio" id="mp3" name="type" checked value="mp3"/>
<label class="circ-btn normal" for="mp3">Mp3</label></p>
<p id="circ">
<input type="radio" id="album" name="type" <?php echo $radio2;?> value="album"/>
<label class="circ-btn normal" for="album">Album</label></p>
</form>
這裏的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci/
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
$ config ['uri_protocol']在您的配置文件中設置爲什麼? – Laurence
$ config ['uri_protocol'] \t ='AUTO'; –
你可以發佈.htaccess文件的內容並仔細檢查以確保mod_rewrite已啓用? –