2012-12-03 42 views
0

我想檢查我的應用程序的所有帖子請求。我創建了一個新的路線選項。如何查看來自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($這個 - > URI-> uri_string)重定向,我得到了一些錯誤頁面。關於不能重新定向自己。

有沒有辦法做到這一點?

回答

1

你這樣做是錯的,它會卡在重定向循環中......在第一次它將總是調用else條件,你已經把重定向...你可以加載一個視圖在其他條件或重定向到其他功能加載視圖。

UPDATE

這是你的工作aorund爲你想達到什麼樣的: 與下面的代碼

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

可惜我不能加載視圖中創建一個post_controller_construct鉤。我想檢查所有的頁面請求。無法爲每個單獨的頁面執行此操作。有沒有什麼辦法可以用額外的參數來改變網址,然後用... – Mifas

+0

是的,你可以通過在函數中傳遞參數來重定向到另一個方法 –

+0

你也可以通過鉤子實現你的目標... check這出[codeigniter掛鉤](http://ellislab.com/codeigniter/user-guide/general/hooks.html) –

相關問題