Retrieve controller namd and function name from url |
[eluser]coldscooter[/eluser]
I am passing a local url to a function in codeigniter as a $_GET parameter. I want to find the controller name and method of the url. I can't just explode by '/' as sometimes i don't specify the function name and allow it to use the index function. Any ideas?
[eluser]CroNiX[/eluser]
Code: echo $this->router->fetch_directory(); //current directory
[eluser]coldscooter[/eluser]
Thanks, but this retrieves data about the requested url. I want to determine the controller and method name of a url string, which may be different from the current.
[eluser]CroNiX[/eluser]
There's nothing that will tell you that from a string. And if there was it would probably be really inefficient. How would knowing this benefit you? What are you trying to accomplish?
[eluser]Aken[/eluser]
CroNIX's method returns the directory, controller and method that is currently being requested, regardless of what the URL says. Sounds like that's exactly what you want...
[eluser]coldscooter[/eluser]
I'm creating a controller to handle ajax calls. I want it to load a library that uses the current controller/method as keys to retrieve particular files. So i just want to be able to parse a url string and pass it what it needs.
[eluser]coldscooter[/eluser]
To clarify: i am posting the 'action' of a form to an ajax controller, and I use that to validate that the data is valid for the controller to receive.
[eluser]coldscooter[/eluser]
This is how i'm handling it at the moment, but i was just hoping for a more elegant CI solution. $formAction = trim(str_replace(site_url(), '', $_REQUEST['formAction']), '/'); $segments = explode('/', $formAction); $formActionController = $segments[0]; $formActionMethod = (empty($segments[1]))?'index':$segments[1];
[eluser]C.T.[/eluser]
if you wish to get the client URL try using URI helper instead? Code: $this->uri->segment(1)
[eluser]coldscooter[/eluser]
It's not the client uri or the url i'm after. It's a string of link into the CI site, so could be of various form. Example: cisite.com/controller1/index http://cisite.com/controller1/ /controller1/ From all these strings, i'd like to be able to determine controller name and method name. For all 3 it should be 'controller1' and 'index' |
Welcome Guest, Not a member yet? Register Sign In |