问题
I usually use something like:
class User extends CI_Controller {
public function save() {
if($this->input->is_post()) { //my own method
......
}
}
}
Is there any other way, eg. in Slim framework:
post("/user/save", function() {
......
});
or in .Net MVC:
[HttpPost]
public ActionResult save(User model) {
......
}
Or can CodeIgniter handle this in its route config file? Thanks for answer.
回答1:
Codeigniter has no built-in support for REST. If you want it, you need to use third-party library or write your own. For third-party library, Here is good one : codeigniter-restserver .
Hope it will be useful for you.
回答2:
To remove index.php
use this in your .htaccess
file
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
来源:https://stackoverflow.com/questions/29159612/codeigniter-how-to-set-a-controller-function-to-be-a-post-route