2012-02-17 62 views
1

這讓我感到困惑。我手動將我的cakephp 1.3應用程序轉換爲2.0以更好地理解它。一切似乎都在工作,但由於某種原因,$ this-> redirect()函數不起作用。它只是留下一個空白的屏幕。cakephp 2.0遷移:重定向不起作用

我的代碼是:

class TimeslotsController extends AppController { 
    var $helpers = array ('Html','Form', 'Calendar'); 
    var $name = 'Timeslot'; 
    var $uses = array('User', 'Timeslot', 'TransLog', 'Credit', 'Section', 'StudentSection', 'Assignment', 'Call') ; 
    var $components = array('Calendar', 'Local', 'Email'); 

    function index() { 
    $this->redirect('admin/user/37'); 
    } 

} 

我失去了對蛋糕2.0如何處理重定向的東西嗎?

謝謝!

+0

你想用這個重定向去哪裏?到UsersController? – nIcO 2012-02-17 07:51:19

+0

爲什麼會有'var $ name ='Timeslot';'。 a)如果有的話,它也應該是複數 b)它應該在2.0全部刪除 – mark 2012-02-17 12:10:21

回答

1

你可以嘗試兩件事。無論使用絕對URL,從而開始了/這樣的:

$this->redirect('/admin/user/37'); 

或(更好的方法),它寫在全面,如:

$this->redirect(array(
    'admin' => true, // Requires admin routing prefix in Config/core.php 
    'controller' => 'user', 
    'action' => 'index', 
    37 
)); 
0

如果在AppController中或在的PageController一個空白,它防止設置標題,因此重定向不起作用。 檢查php代碼之前的空白,如果以上所有syntex都不起作用