0

使用 codeigniter 我在后端传递变量时遇到问题,例如

http://localhost:4949/admin/delete_post/6/?action=delete

生产The URI you submitted has disallowed characters.

我知道这个问题可以从 config.php 得到纠正$config['permitted_uri_chars'],但我怎么能排除过滤我的后端并允许这种结构并保持前端完好无损。

4

2 回答 2

0

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

于 2013-03-28T09:07:18.730 回答
0

像这样与与号 (&) 一起使用

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_+&-';

它可能会解决您的问题。

详细解释在这里

于 2013-03-26T01:24:47.907 回答