我不擅长 php,而 codeigniter 给了我最大的帮助。我的网站是一个搜索引擎,在我进行搜索后,我的网站的网址是这样的:mysite.com/ ?search=eminem&type=mp3 ,我不喜欢它。我想这样做,所以当我输入 search eminem 给我这个网址时:mysite.com/eminem/mp3 这是来自 CI 的代码
<?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>