CodeIgniter Forums
parameter for default controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: parameter for default controller (/showthread.php?tid=24910)



parameter for default controller - El Forum - 11-24-2009

[eluser]aryan_[/eluser]
I have created a default controller 'Pages'. How do I pass parameter to index of this controller?

i.e. http://example.com/param1/param2

I need this only for default controller.

Please help. Thanks!


parameter for default controller - El Forum - 11-24-2009

[eluser]Isern Palaus[/eluser]
[quote author="aryan_" date="1259077368"]I have created a default controller 'Pages'. How do I pass parameter to index of this controller?

i.e. http://example.com/param1/param2

I need this only for default controller.

Please help. Thanks![/quote]

Hi,

you can use:

$param1 = $this->uri->segment(1);
$param2 = $this->uri->segment(2);

in your index() function.

Wish it helps!
Isern


parameter for default controller - El Forum - 11-24-2009

[eluser]aryan_[/eluser]
Quote:you can use:

$param1 = $this->uri->segment(1);
$param2 = $this->uri->segment(2);

in your index() function.

Wish it helps!
Isern

But, It'll look for controller for segment1 and function for segment2!

I've got a little success using route:

$route['pages/:any'] = "pages/index/$1";

I can remove 'pages/' to achieve this, but what about other controllers?


parameter for default controller - El Forum - 11-24-2009

[eluser]jedd[/eluser]
You are allowed, nay encouraged, to use the [url="/forums/search/"]search feature[/url] within the forums.

This was posted and answered (probably for the umpteenth time) just ten days ago in the thread titled [url="/forums/viewthread/135187/"]Parameters to Controller index()[/url] (alarmingly close to parameter for default controller, eh?).