CodeIgniter Forums
help with routes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: help with routes (/showthread.php?tid=62493)



help with routes - GoncaloF - 07-21-2015

in routes.php i have:

PHP Code:
$route['admin/orders'] = 'admin_orders/index';
$route['admin/orders/(:any)'] = 'admin_orders/index';
$route['admin/orders/getAll'] = 'admin_orders/getAll';
$route['admin/orders/getLast'] = 'admin_orders/getLast';
$route['admin/orders/delete/(:any)'] = 'admin_orders/delete'


in admin_orders.php i have:

PHP Code:
public function delete(){
        
$id $this->uri->segment(4);
         echo 
"ok   $id";
   } 


and in the view:

Code:
<a href="'.site_url("admin").'/orders/delete/3'.'" class="btn btn-info">Delete</a>


and when i press the Delete the app reload the page, and if i try without the /(:any) the function loads, how i can load the function with a parameter?


RE: help with routes - pdthinh - 07-21-2015

I think you should move the 2nd route to last.

PHP Code:
$route['admin/orders'] = 'admin_orders/index';
$route['admin/orders/getAll'] = 'admin_orders/getAll';
$route['admin/orders/getLast'] = 'admin_orders/getLast';
$route['admin/orders/delete/(:any)'] = 'admin_orders/delete'; 
$route
['admin/orders/(:any)'] = 'admin_orders/index'// moved to last 



RE: help with routes - Avenirer - 07-22-2015

You should also move the first line to be the last.


RE: help with routes - Dracula - 07-22-2015

(07-21-2015, 04:34 PM)GoncaloF Wrote: in routes.php i have:


PHP Code:
$route['admin/orders'] = 'admin_orders/index';
$route['admin/orders/(:any)'] = 'admin_orders/index';
$route['admin/orders/getAll'] = 'admin_orders/getAll';
$route['admin/orders/getLast'] = 'admin_orders/getLast';
$route['admin/orders/delete/(:any)'] = 'admin_orders/delete'


in admin_orders.php i have:


PHP Code:
public function delete(){
 
       $id $this->uri->segment(4);
 
        echo "ok   $id";
 
  


and in the view:


Code:
<a href="'.site_url("admin").'/orders/delete/3'.'" class="btn btn-info">Delete</a>


and when i press the Delete the app reload the page, and if i try without the /(:any) the function loads, how i can load the function with a parameter?


Why don't you do it like this:

Code:
$route['admin/orders/delete/(:any)'] = 'admin_orders/delete/$1';

For your delete method:

PHP Code:
public function delete($id){
 
        echo "ok   $id";
 
  

And in your view:

PHP Code:
<a href="'. site_url('admin/orders/delete/') . $id . '" class="btn btn-info">Delete</a