• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Confused about Routes..

Her is my confusion.. any help will be appreciated..

1. my default in route.php is $route['default_controller'] = 'home/main'; (This is the home page and needs no authintication.

2. i have a menu link to my content and the uri is /mycontent

3. On mycontent controller i have the following.....

function index()
# // Check if user is logged in or not
if ($this->authlib->check())

{ $data = "blah......"
$this->load->view('AddContent', $data);

$route['home'] = "home/main";

4. It never loads the AddContent View.. it always goes to Home/Main Controller.

5. If I change the default route to mycontent then it works....


the quick answer is that routes are loaded before the controller and determine which controller the URI info should be sent to.

What is it you are trying to achieve?

This: $route[‘default_controller’] = ‘home/main’; is a route which maps a URI (yoursite.com/)`default_controller` to a controller and action `home/main`. Which is a bit strange isn't it?

Go like this:

$route['your_url'] (refers to http://www.yoursite.com/your_url)
$route['your_url/(:any)'] (refers to http://www.yoursite.com/your_url/anystringhere)
$route['default_controller'] (refers to http://www.yoursite.com, this is a reserved name so that you don't have to fill in an empty url like: $route[''])

you should 'map' the routes above to a Controller action (function) (in your case 'MyContent' and 'index'):

$route['default_controller'] = 'mycontent/index'; (you can optionally leave index away, because it is default)

NOTE: Codeigniter has some built-in URI mapping so that every url automatically maps to controllers / actions. This works automatically...

It works like this: yoursite.com/controller/[action/parameters*]
this automatically maps to Controller->Action($parameters)

you can play around with that because:
yoursite.com/controller -> maps to Controller->index()
yoursite.com/controller/action/p1/p2/p3/p4 -> maps to Controller->action($p1,$p2,$p3,$p4)

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.