Php标头不起作用,标头未发送

时间:2015-07-17 08:12:23

标签: php html redirect

我正在为模板引擎编码,因此我已经成功了:

public function getFilename() {
    $config = new Config('template_config.ini');
    if($this->filepath == null){
        $this->filename = $config->get("file")["default"];
    }else{
        if(array_key_exists($this->filepath, $config->get("file"))){
            $this->filename = $config->get("file")[$this->filepath];
        } else {
            Redirect::to("/404");
            return $this;
        }
    }
    return $this;
}

代码运行良好,直到它不再存在。它运行到右侧框,并运行等于:header("Location: ".$input); exit;的重定向功能。在标题之后它回显了事情,标题只是没有链接。

这一切都在索引中调用:

use lib\Template\Template_loader;
use lib\Api\Input;
require_once("Nytrix/autoloader.php");
new Template_loader(Input::get("path"));

然后调用构造函数,调用文件名函数:

public function __construct($filepath){
    $this->filepath = $filepath;
    $this->getFilename();

}

Redirect::to($argument);功能是:header("Location: ".$argument);。没有实施laravel

1 个答案:

答案 0 :(得分:1)

这段代码有点偏。调用Redirect::to("/404");不会设置标题或任何内容。它生成一个需要从控制器返回的Illuminate\Http\RedirectResponse对象。