我已經完成了CI文檔中包含的着名的'新聞'toutorial。有時會在我的鏈接字符串中出現雙「新聞/」段,如'/ codeig/news/news/entry',有時在重新加載頁面之後,一切正常。我應該提到,我已經擺脫了'index.php'部分繼另一個受歡迎的教程。我的代碼有什麼問題?Codeigniter的網址翻倍,比如:news/news/
這是我的路由:
$route['news/create'] = 'news/create';
$route['news/update/(:any)'] = 'news/update/$1';
$route['news/delete/(:any)'] = 'news/delete/$1';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['welcome'] = 'welcome';
$route['auth/(:any)'] = 'auth/$1';
$route['auth'] = 'auth';
$route['activate/:num/:any'] = "/auth/activate/$1/$2";
$route['reset_password/:num/:any'] = "/auth/reset_password/$1/$2";
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'news';
視圖/消息/ index.php文件:
<?php foreach ($news as $news_item): ?>
<h2><?php echo $news_item['title'] ?></h2>
<div id="main">
<?php echo $news_item['text'] ?>
</div>
<p><a href="news/<?php echo $news_item['slug'] ?>">View article</a></p>
<?php endforeach ?>
視圖的方法(新聞控制器)
public function view($slug)
{
$data['news_item'] = $this->news_model->get_news($slug);
if (empty($data['news_item']))
{
show_404();
}
$data['title'] = $data['news_item']['title'];
$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
}
我們不能告訴你的代碼有什麼問題,因爲你沒有向我們展示任何... – Mudshark 2012-03-31 14:52:19
好吧,那是從原始CI文檔中獲取的代碼。 – kurdt 2012-03-31 15:03:01
你是如何構造輸出加倍段的URL,即'news/news /'?你可以發佈該代碼嗎? – 2012-03-31 15:44:26