php - Codeigniter routing causes function to be called multiple times -


i have function called "insert" in categories controller. when call function via url this: /categories/insert works ok, if call function this: /categories/insert/ (slash @ end) function called 3 times.

even when call edit function this: /categories/edit/2 - edit function called 3 times.

in config/routes.php have default route. .htaccess this:

rewriteengine on rewritecond $1 !^(index\.php|images|include|robots\.txt) rewriterule ^(.*)$ /index.php/$1 [l]   

edit:

the code edit function:

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     } } 

** edit ** http://your.dot.com/insert calls public function insert($arg) without data $arg. http://your.dot.com/insert/ calls insert 'index.php' $arg.

routes.php

$route['edit/(:any)'] = 'edit/$1' 

accepts param coming query string: yoursite.com/edit/param or yoursite.com/edit/2
requires method named edit.

if using $route=['default_controller'] = 'foo', container of methods, change route $route['edit/(:any)'] = 'foo/edit/$1' or like: $route['(:any)'] = 'foo/$1/$2' last line of routes (note: work yoursite.com/insert/param , yoursite.com/edit/param.

foo.php      public function insert() { ... }      public function edit($id=null) { ... }      /* end of file foo.php */   .htaccess      rewritecond $1 !^(index\.php)     rewritecond %{request_filename} !-f     rewritecond %{request_filename} !-d     rewriterule ^(.*)$ /index.php?$1 [l] 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -