我在我的类别控制器中有一个名为“插入”的函数。当我通过这样的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