0

I am working with CodeIgniter. Here's my routing file

    $route['default_controller'] = 'pages/view/home';
    $route['(:any)'] = 'pages/view/$1';

where

pages is the controller class and view is a function of it and home is a parameter to that function.

Now, this is the default controller. When i need to open someother page rather than 'home' I do it like as follows from inside a view

href="<?php echo base_url('products');?>

Now what i want to ask is, if i create a new controller, how can i use the function of that controller? since I am only passing the third parameter to the base_url() function.

Obviously I think I gotta write $routes, but how ? since all the traffic is passed to

pages/view

I tried creating a new controller but couldn't be able to use it. My new contoller was name new_controller and it has a function call new_function()

and I wrote the $route as follows

$route['pages/view/product'] = 'new_controller/new_function';

tereško
  • 58,060
  • 25
  • 98
  • 150
Saaram
  • 337
  • 3
  • 7
  • 29

2 Answers2

1

You shouldn't have to worry about Routes if you take away the (:any) route you have place there. That is blocking all other controllers from being loaded, I think.

If you have a controller called "Stuff"

in your URL when you have mysite.com/stuff/foo/param Code Igniter should bypass the default "page" controller and use

I think you would be better off doing something like this

$route['page/(:any)'] = "page/view/$1";

And change your default to be only 'pages'

That would open up your new controller to be used in the normal codeigniter fashion

Dameo
  • 334
  • 2
  • 7
0

In CodeIgniter the routes are evaliated in row, so first you have the default route and after that sould you place the new route, $route['pages/view/product'], if you want to keep the (:any) route, and with this, you place the exceptional routes before the (:any) route.

ghostika
  • 1,473
  • 1
  • 12
  • 23