我的分类控制器中有一个名为“insert”的函数。当我通过网址调用该函数,如/categories/insert时,它可以正常工作,但是如果我像这样调用函数:/categories/insert/(末尾带斜杠),则该函数会被调用三次。
即使我像这样调用编辑功能:/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
}
}