Welcome Guest, Not a member yet? Register   Sign In
$route[':any'] issue
#1

[eluser]EEssam[/eluser]
Hi,

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

www.mydomain.com/[page_name_in_db]

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?

Thanks.
#2

[eluser]Randy Casburn[/eluser]
Hi,
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.

Randy
#3

[eluser]Randy Casburn[/eluser]
EEssam,

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

here is your fix:

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

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.

Randy
#4

[eluser]EEssam[/eluser]
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:

<?php

class Welcome extends Controller {

function Welcome()
{
parent::Controller();

$this->load->scaffolding('category');
}

function index()
{
$this->load->view('welcome_message');
}

function inde22x()
{
echo 'g';
}

function page_lookup()
{
echo 'cool';
}


}
#5

[eluser]Randy Casburn[/eluser]
Wow,

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.

Randy
#6

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

[eluser]EEssam[/eluser]
I just got the not found page.

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

[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:

[':any']

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

[eluser]EEssam[/eluser]
Right.
#10

[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?




Theme © iAndrew 2016 - Forum software by © MyBB