使用 codeigniter 我在后端传递变量时遇到问题,例如
http://localhost:4949/admin/delete_post/6/?action=delete
生产The URI you submitted has disallowed characters.
我知道这个问题可以从 config.php 得到纠正$config['permitted_uri_chars']
,但我怎么能排除过滤我的后端并允许这种结构并保持前端完好无损。
使用 codeigniter 我在后端传递变量时遇到问题,例如
http://localhost:4949/admin/delete_post/6/?action=delete
生产The URI you submitted has disallowed characters.
我知道这个问题可以从 config.php 得到纠正$config['permitted_uri_chars']
,但我怎么能排除过滤我的后端并允许这种结构并保持前端完好无损。
This kind of formatting is not necessary in Codeigniter. Although query strings can be enabled, using them in my opinion goes against codeigniters way of handeling things. As you can pass variables from your views via uri.
http://yourdomain_baseurl/controller/controller_function/var1/var2/var3
I suggest doing the following:
Send variables in an url like this:
http://yourdomain_baseurl/admin/post_action/id/action
in your 'admin' controller, you can create something like this:
function post_action($id, $action){
switch ($action) {
case "delete":
//do something here with your post with id $id
break;
case "update":
//do something here with your post with id $id
break;
case "create":
//do something here with your post with id $id
break;
}
}
Or if you like to create a seperate function for each Post action:
http://yourdomain_baseurl/admin/post_delete/id
http://yourdomain_baseurl/admin/post_edit/id
With the following functions in your admin controller
function post_delete($id){
//Delete Archive the post with $id here!
}
function post_edit($id){
//edit the post with $id here!
}
As most user input comes from forms, you can use $_POST data get user input. There is a usefull class to help you out:
$this->input->post('some_data');
I suggest reading the documentation that comes with codeigniter and read the following:
URL's http://ellislab.com/codeigniter/user-guide/general/urls.html
URls http://ellislab.com/codeigniter/user-guide/general/routing.html