• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$route[':any'] issue


I would like to pull pages from the database and give direct links:


So I created the following rule in routes file:

$route['default_controller'] = "welcome";
$route[':any'] = "welcome/page_lookup";

Now none of my controllers are being called, not even functions in my "welcome" controller. How can I fix that?


[eluser]Randy Casburn[/eluser]
you're trying to...

Looked at the source and what you're trying should work. There is something else a miss.

Need more info. Put just the structure (not the entire thing) of your welcome class file in code tags here. lets have a look.


[eluser]Randy Casburn[/eluser]

OK. Number of left_hand route arguments mustequal number of right_hand arguments ... so:

here is your fix:


essentially will take a URL http://yourdomaindotcom/fred and invoke the page_lookup method of the welcome controller class. Presumably you would then use $this->uri->segment(1) to retrieve the page named 'fred' from the table of your choice.

There you have it.

I had solved this a different way. Thanks for you help.


Thanks Randy, but it didn't work, I'm getting a not found error:

$route['default_controller'] = "welcome";
$route['scaffolding_trigger'] = "scaffolding";

$route[':any/:any'] = "welcome/page_lookup";

My Welcome controller:


class Welcome extends Controller {

function Welcome()


function index()

function inde22x()
echo 'g';

function page_lookup()
echo 'cool';


[eluser]Randy Casburn[/eluser]

I don't really recommend anyone doing this...ever. Just found out why this never crossed my mind. This construct sort of throws all the flexibility of CI on the floor.

Would be better to come into the default controller and branch from there the way CI is designed to operate.

Just my two cents FWIW.


[eluser]Randy Casburn[/eluser]
Do you see the welcome message? -- it may be the 'echo' is 'under' (z-index layed) the other content.

I just got the not found page.

So, what is the correct way to accomplish the task then?

[eluser]Randy Casburn[/eluser]
Let's start by commenting out the load->scaffolding call from the constructor for now.
I confirmed that only ONE :any wild card is required, so let's remove the first :any and the slash, back to your original code:


The php file named welcome_message.php does actually exist in your views directory, right?


[eluser]Randy Casburn[/eluser]
Hi EEssam,

um...are you getting the big fat ugly Object not Found error...or the pretty CI error surrounded by the red box?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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