如何在 Codeigniter 的多个环境检查中加载视图或使用 redirect()?

How to load view or use redirect() inside multiple environment check in Codeigniter?

想要检查环境,如果匹配某些情况,则想要重定向或加载某些视图。 get_instance(); 无法在环境检查的 index.php 内部工作
我看起来像下面这样:

if (ENVIRONMENT === "production")
{

    /*if(error ="db error")
    redirect("/someview","refresh");
    or load view header and footer
    */

}

i just confused about error handling mechanism in CI. By the help of Whosebug users i found steps to turn off the errors . but now i can't handle those errors.

如果你想处理某个错误,你可以将它重定向到流程中的某个视图,就像你在问题中提到的那样。

 // Assuming you have a [Home] Controller that extends to your [Common] parent class
 class Home extends Common {
    public function index()
    {
        $this->load->helper('url');
        $bCheck = false;
        if ($bCheck !== true) {
            $this->handleRedirectMethod('path/to/your/controller');
        }
    }
}

然后在你的父 [Common] 控制器上。 (例如 Common.php)

class Common extends CI_Controller
{
    public function handleRedirectMethod($sUrl, $sMethodName = 'refresh', $sStatusCode = '302')
    {
        $sServerName = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
        redirect($sServerName . '/' . $sUrl, $sMethodName, $sStatusCode);
    }
}

希望这能让您了解如何处理这些错误