Welcome Guest, Not a member yet? Register   Sign In
How to pass a parameter directly to the default controller
#1

[eluser]Shiju S S[/eluser]
I need to pass a parameter directly to the default controller

like
quickbharat.com/shiju

I defined routes like
Code:
$route['default_controller/frontpage/(:any)'] = "frontarea/frontpage/some/$1";
$route['default_controller/(:any)'] = "frontarea/frontpage/some/$1";
$route['default_controller'] = "frontarea/frontpage";

404 error occurs. What to do sir?
#2

[eluser]InsiteFX[/eluser]
Code:
// replace default_controller with shiju
$route['controller_name/method'] = '';
#3

[eluser]Shiju S S[/eluser]
The name coming after the default controller is a variable

I want to pass like

quickbharat.com/research associate
quickbharat.com/lab assistant
quickbharat.com/shiju

My default controller now points to:
Code:
$route['default_controller'] = "frontpage";

frontpage is the controller loaded first. How can I call a method in that controller directly without using

Code:
$route['frontpage/(:any)'] = "frontarea/frontpage/somefunction/$1";

#4

[eluser]InsiteFX[/eluser]
Spaces will show up as so your url will end up looking like research associate
Better to use an under score then it will look like research_associate

CodeIgniter Routes Trick – Removing Controller Names from the URI to Keep URLs Short.
#5

[eluser]Shiju S S[/eluser]
Sir actually i want to pass a parameter to the default controller like this


Code:
http://example.com/param1/param2

I did like this

Code:
public function index()
{
$param1 = $this->uri->segment(1);
$param2 = $this->uri->segment(2);
}

Is there any other way like defining a separate controller to handle it in the routes.
like
Code:
$route['default_controller/(:any)'] = "frontpage/some/$1";
#6

[eluser]Shiju S S[/eluser]
Thank you sir for I got it solved with this simple thing

folder - frontarea
controller - frontpage
function - somefunction

$route['(:any)'] = "frontarea/frontpage/somefunction/$1";
#7

[eluser]CroNiX[/eluser]
That will work unless you have more than one controller (unless you have routes defined for those before your catch-all route)




Theme © iAndrew 2016 - Forum software by © MyBB