Possible Duplicate:
Headers already sent by PHPCakePHP的重定向不工作
我不知道,但前一段時間,重定向功能工作。但現在它給了我這個錯誤:
Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\NewFolder\app\webroot\relationship1\app\controllers\books_controller.php:114) [CORE\cake\libs\controller\controller.php, line 744]
這是我的控制器:C:\ XAMPP \ htdocs中\ NewFolder \程序\ webroot的\試用\程序\控制器\ users_controller.php中
<?php
class UsersController extends AppController{
function register(){
if(!empty($this->data)){
if($this->User->save($this->data)){
$this->Session->setFlash('Data saved');
$this->redirect(array('action'=>'index'));
} else{
$this->Session->setFlash('Could not save data');
}
} else{
$this->Session->setFlash('Please fill this form');
}
}
function index(){
$users = $this->User->find('all');
$this->set('users',$users);
}
function login(){
//$this->Session->write('user','chams');
//pr($this->Session->read());
if(!empty($this->data)){
//pr($this->data['User']['username']);
$username = $this->data['User']['username'];
//if($this->User->read(NULL,$username)){
//$condition = array('User.username'=>$username);
if($this->User->findByUserName($username)){
pr('existing');
$data = $this->User->find('first',$username);
$this->set('data',$data);
if($this->redirect(array('action'=>'main'))){
$this->Session->setFlash('redirected to index');
}
} else{
pr('non existing');
}
}
}
}
?>
在登錄你的問題重定向? – thecodeparadox
重複。你不能在重定向頭之前輸出任何東西到屏幕上......從你的php文件中刪除所有關閉的'?>'!也許這是其中一個造成這種情況後的空白。 – mark