0

我想检查我的应用程序的所有发布请求。我创建了一个新的路线选项。

$route['(:any)'] = 'any';

这将调用任何控制器。这是我的 any.php

if ( !defined('BASEPATH') ) exit('No direct script access allowed');

class Any extends CI_Controller {

    public function __construct() {
        parent::__construct();

    }


    function index(){
        if(  $_POST ){
            if( validate() ){
                // redirect to error controller
            }else{
                //redirect to current page url
            }
        }else{
            //redirect to current page url
        }
    }
}

但是当我通过这个函数重定向($this->uri->uri_string)重定向时,我得到了一些错误页面。关于不能重定向到它自己。

有没有办法做到这一点?

4

1 回答 1

1

你做错了它会卡在一个重定向循环中......在第一次之后它总是会调用你放置重定向的 else 条件......你可以在 else 条件下加载视图或重定向到你所在的其他函数加载视图。

更新

这是您要实现的目标的工作: Create a post_controller_construct hook with following code

class validate_post_request
{
    function validate_request()
    {
        //Here i am supposing your validate function is in helper 
        //which is included in autoload. The function returns
        //true if validation passed and false on failure
        if( !validate() ) {
            show_error('Your error message to display');
            exit;
        }
    }
}
于 2012-12-03T05:43:58.180 回答