Welcome Guest, Not a member yet? Register   Sign In
Routes, how to handle empty strings? [SOLVED, with hack]
#1

[eluser]xzela[/eluser]
Hi all,

I'm trying to use the routing feature in CI and I'm having an issue with handling empty strings with the (:any) flag.

Here is what I'm trying to accomplish:

When a user goes to the URI http://localhost/pages/cake-types I want to show the user a list of cake types. However, when the user goes to the URI http://localhost/pages/cake-types/cupcakes it should the appropriate page (a page related to cupcakes).

The above works (kind of). The issue is when a user goes to http://localhost/pages/cake-types they get a 404 Page Not Found message. Yet, when the user goes to 'child page' like http://localhost/pages/cake-types/cupcakes it works as expected.

What is it about my routes file? How do you set it so empty strings are treated correctly?

routes.php //routes file
Code:
$route['pages/cake-types/(:any)'] = 'pages/cake_types/$1';

pages.php //controller file
Code:
//...
public function cake_types($type = null) {
  if($type == null) {
     $this->load->view('pages/cakes/cake_type_list_view');
  }
  else if ($type == 'cupcakes') {
     $this->load->view('pages/cakes/cupcakes_view');
  }
  //... more if conditions
}
//...

Any information you can lend will be much appreciated.

Thanks


Messages In This Thread
Routes, how to handle empty strings? [SOLVED, with hack] - by El Forum - 07-23-2010, 11:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB