我正在尝试在重定向后创建会话闪存消息。
我有控制器类
class Controller
{
function __construct()
{
if(!empty($_SESSION['FLASH']))
foreach($_SESSION['FLASH'] as $key => $val)
$this->$key = $val;
}
function __destruct()
{
$_SESSION['FLASH']=null;
}
}
我也有 Controller 子类 Home,其中函数通过路由运行,例如 /Home/Index => public function index()
class Home extends Controller
{
function __construct()
{
parent::__construct();
}
public function index()
{
//where i want to display $this->message only once
echo $this->message; // but $this->message is undefinded why?
}
public function Post_register(){
//after post form data
// validation
// this function redirect to /Home/Index above function index();
Uri::redirectToAction("Home","Index",array('message' => 'some message'));
}
}
和 uri 类函数,我在其中重定向用户。
public static function redirectToAction($controller,$method,$arr)
{
$_SESSION['FLASH'] = $arr;
header("Location:/".$controller.'/'.$method);
}
但$this->message
不确定为什么?