我在我的類別控制器中有一個名爲「插入」的函數。當我通過這樣的url調用函數時:/ categories/insert它工作正常,但是如果我像這樣調用函數:/ categories/insert /(最後的斜槓),函數被調用三次。Codeigniter路由導致函數被調用多次
即使打電話給我這樣的編輯功能:/ categories/edit/2 - 編輯功能被調用三次。
在config/routes.php中我只有默認路由。我的.htaccess是這樣的:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|include|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
編輯:
的編輯功能的代碼:
public function edit($id = '')
{
$this->load->helper("form");
$this->load->library("form_validation");
$data["title"] = "Edit category";
$this->form_validation->set_rules('category_name', 'Category name', 'required');
if (!$this->form_validation->run())
{
$data['category'] = $this->categories_model->get_categories($id);
$this->load->view("templates/admin_header", $data);
$this->load->view("categories/edit", $data);
$this->load->view("templates/admin_footer", $data);
}
else
{
$this->categories_model->update($id);
// other logic
}
}
你怎麼能說其所謂的三次呢,你可以發佈您的代碼? – Sudz 2013-05-10 14:24:46
我知道,因爲我對代碼的第一行設置斷點。我用函數的代碼編輯了我原來的帖子,我認爲它與代碼沒有任何關係,因爲當我調用插入函數而不在網址末尾使用斜線時,它可以正常工作。 – Andrej 2013-05-10 15:00:00
你的路線是什麼樣的? – Dawson 2013-05-10 17:55:08