Welcome Guest, Not a member yet? Register   Sign In
Can you run different controller methods for POST and GET?
#1

[eluser]Unknown[/eluser]
Having previously used the DooPHP framework, I am making the move to CodeIgniter, as it has been recommended to me by my colleagues.

Similarly to DooPHP, CodeIgniter has a routes config file, which can take a list of URI/method pairs.

In DooPHP, you could have a basic get request to 'http://www.mysite.com/sign-up' run a method in the controller called "signUp" and a post request to the same URL run a different method. i.e. "postSignUp", as show below.

$route['get']['/sign-up'] = array('PublicController', 'signUp');
$route['post']['/sign-up'] = array('PublicController', 'postSignUp');

Is it possible to do this at routes level in CodeIgniter, without having to do some conditional logic in the controller itself? I can't see anything like this in the documentation - hopefully someone can enlighten me to what I am hoping to be true! Smile

Cheers
#2

[eluser]CroNiX[/eluser]
CI doesn't have that functionality built in. You could extend the router class and add it in though. I've not used this extension, but on github I've seen where somebody extended CI to basically work just like laravel routes including restful routes, filtering, etc: https://github.com/Patroklo/codeigniter-...vel-routes
#3

[eluser]Narf[/eluser]
CI 3.0-dev has this functionality.
#4

[eluser]ivantcholakov[/eluser]
"Using HTTP verbs in routes"?
Edit: https://github.com/EllisLab/CodeIgniter/...outing.rst




Theme © iAndrew 2016 - Forum software by © MyBB