參數(shù) | 說明 |
url | 必須,重定向的 URL 表達式。 |
params | 可選,其它URL參數(shù)。 |
delay | 可選, 重定向延時,單位為秒。 |
msg | 可選,重定向提示信息。 |
ThinkPHP redirect 實例
在 Index 模塊 index 方法中,重定向到本模塊的 select 操作:
class IndexAction extends Action{ public function index() { $this->redirect('select', array('status'=>1), 3, '頁面跳轉(zhuǎn)中~'); //3秒 } }
一些常用的 redirect 重定向例子:
// 不延時,直接重定向 $this->redirect('select', array('status'=>1)); // 延時跳轉(zhuǎn),但不帶參數(shù),輸出默認提示 $this->redirect('select', '', 3); // 重定向到其他模塊操作 $this->redirect('Public/login'); // 重定向到其他分組 $this->redirect('Admin-Public/login');
提示:
1. 當延時跳轉(zhuǎn)時,必須輸入 params 參數(shù)(可以為空),也就是 delay 必須出現(xiàn)在第 3 位上。
2. 如果發(fā)現(xiàn)跳轉(zhuǎn)后的 URL 有問題,由于 redirect 方法調(diào)用 U 方法來生成跳轉(zhuǎn)后的地址,這時候可以測試一下 U 方法生成的地址是否正確,再檢查一下系統(tǒng)配置。
更多關于thinkPHP相關內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術總結》。
希望本文所述對大家基于ThinkPHP框架的PHP程序設計有所幫助。