CodeIgniter: How to set a controller function to be a post route?

蹲街弑〆低调 提交于 2020-02-08 07:22:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!