Php 代码点火器重定向不工作

Php 代码点火器重定向不工作,php,codeigniter,Php,Codeigniter,为什么重定向在这里不起作用。正在调用未定义的函数redirect() 您没有在authenticate方法中加载URL帮助程序。您必须将$this->load->helper('URL')添加到类构造函数中(看起来像是您在尝试这么做),或者必须将其添加到authenticate方法本身 只是提醒一下,index方法是一种特殊的方法——在没有指定其他方法时调用它。使用URL/login/,将触发索引。除此之外,它将被忽略。将authenticate()方法上方的顶部更改为此 class Login

为什么重定向在这里不起作用。正在调用未定义的函数redirect()


您没有在
authenticate
方法中加载
URL
帮助程序。您必须将
$this->load->helper('URL')
添加到类构造函数中(看起来像是您在尝试这么做),或者必须将其添加到authenticate方法本身


只是提醒一下,
index
方法是一种特殊的方法——在没有指定其他方法时调用它。使用URL
/login/
,将触发索引。除此之外,它将被忽略。

authenticate()
方法上方的顶部更改为此

class Login extends CI_Controller {

    function __construct()
    {
        // this is your constructor
        parent::__construct();
        $this->load->helper('form');
        $this->load->helper('url');
    }

    function index()
    {
        //this is only called when someone does not specify a method...
        $this->load->view('login_view');        
    }
...

我强烈建议将这两个助手移动到自动加载状态,因为它们几乎需要大量的使用…

您的逻辑是正确的,但是,在构造函数中加载一些助手和模型时,有时会出现一些缺点

尝试从函数中加载帮助程序。

尝试:

function __construct() {
    parent::__construct();
    $this->load->helper('form');
    $this->load->helper('url');
}
如果您的服务器是windows,请尝试:

redirect('/site/news_feed','refresh');
你需要一个地方

$this->load->helper('url');
在重定向函数之前

redirect() belong to url helper.
每次你需要它的时候,你都可以这样加载它

$this->load->helper('url');
或者最好是全局加载,这样就不需要一次又一次地加载

//application/config/autoload.php
$autoload['helper'] = array("url");
这些“缺点”的例子?
//application/config/autoload.php
$autoload['helper'] = array("url");