EllisLab text mark
Advanced Search
2 of 2
2
   
Basic index($variable) question for creating a site like www.mysite.com/username
Posted: 12 November 2012 06:23 PM   [ # 16 ]   [ Rating: 0 ]
Joined: 2012-10-08
15 posts
PhilTem - 12 November 2012 05:38 PM

Maybe you want to have a look at this kinda tutorial I wrote some months ago for other people having the same problem:

http://files.ignitedco.de/codeigniter/tutorials/static-pages-routing.html

It does not match your problem perfectly, but you might understand how the added route works.

BTW: Every route that you add must go after the default_controller and 404_override route. And watch out to take the correct apostrophes - PHP uses quotation marks and no apostrophes wink


I looked at your tutorial and noticed you have some constructor code.  But the CI User Guide does not have the constructor at the beginning here: http://ellislab.com/codeigniter/user-guide/general/controllers.html  It does mention contractors later on but I’m not familiar enough with CI to know if the following constructor code is always required: 

public function __construct()
  {
      parent::__construct();
  }

I don’t have this in my controllers…do I require it?

 
Posted: 12 November 2012 06:25 PM   [ # 17 ]   [ Rating: 0 ]
Joined: 2012-10-08
15 posts
siptik - 12 November 2012 04:41 PM

you need to add route for each controllers

Can you please help me with what code I need to repeat for each controller?

 

 
Posted: 12 November 2012 06:44 PM   [ # 18 ]   [ Rating: 0 ]
Joined: 2012-10-08
15 posts
AlanW - 12 November 2012 04:20 PM
AlanW - 12 November 2012 04:14 PM

Thanks!

siptik - 12 November 2012 04:12 PM

try this:

$route[‘default_controller’] “main”;
route $route["(:any)"‘main/index/$1’
$route[‘404_override’] 
‘’

Do you mean ‘set route $route[”(:any)”] = ‘main/index/$1’ …?

 

Actually, I wondered if you need the word ‘set’ … or route.

It looks like the other lines start with $route so I’ll try adding:

$route[”(:any)”] = ‘main/index/$1’;


Thanks again.  I am really trying to understand the (:any) piece here to get my http://www.mysite.com/username and also allow other controllers.  It doesn’t appear to me that what I want to do is an easy task.  For others, I’m including this reference here:

At http://ellislab.com/codeigniter/user-guide/general/routing.html they describe this:

$route[‘product/(:any)’] = “catalog/product_lookup”;
A URL with “product” as the first segment, and anything in the second will be remapped to the “catalog” class and the “product_lookup” method.

$route[‘product/(:num)’] = “catalog/product_lookup_by_id/$1”;
A URL with “product” as the first segment, and a number in the second will be remapped to the “catalog” class and the “product_lookup_by_id” method passing in the match as a variable to the function.

 

 
2 of 2
2