CodeIgniter Forums
Pass url parts as array to 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: Pass url parts as array to controller (/showthread.php?tid=52715)



Pass url parts as array to controller - El Forum - 06-23-2012

[eluser]Unknown[/eluser]
Best,

I was wondering if it is possible to pass the whole url in array form to the called controller method.

so for example if I call
Code:
/controller/action/param1/param2/param3
I don't wish to catch those by creating

Code:
public function action($param1, $param2, $param3)

But rather

Code:
public function action($params)

This because I do not know in advance how many parameters will be passed through.

Thanks!
Pj


Pass url parts as array to controller - El Forum - 06-23-2012

[eluser]mschinis[/eluser]
you can use:
Code:
$this->uri->uri_to_assoc(n)

that will give you an associative array back. Refer to this page:
http://ellislab.com/codeigniter/user-guide/libraries/uri.html


Pass url parts as array to controller - El Forum - 06-23-2012

[eluser]Unknown[/eluser]
Hey mschinis,

uri_to_assoc wasn't exactly what I was looking for but on the page you provided I found the function

Code:
$this->uri->segment_array()

That did the job.

Thanks!


Pass url parts as array to controller - El Forum - 06-23-2012

[eluser]mschinis[/eluser]
Great :lol:

glad you figured it out Smile