簡體   English   中英

如何檢查來自CodeIgniter的所有發帖請求

[英]How to check all post request from CodeIgniter

我想檢查我的應用程序的所有發帖請求。 我創建了一個新的路線選項。

$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
        }
    }
}

但是當我通過該函數rediect($ this-> uri-> uri_string)重定向時,出現了一些錯誤頁面。 關於不能重定向到自己。

有什么辦法嗎?

您做錯了,它將停留在重定向循環中...第一次后,它將始終調用您已放置重定向的else條件。加載視圖。

更新

這是您要實現的目標工作:用以下代碼創建一個post_controller_construct鈎子

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;
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM