如何将变量值从控制器发送到cakephp3中的另一个不同视图?
问题描述:
I have two controller and two view in my cakephp3.
My 1st controllers and views are:
1.importController.php , index.ctp;
And my 2nd controllers and views are:
2.titlesController.php , success.ctp;
Now I want to send variable value (such as $data=5) from importController.php to success.ctp view.
我的cakephp3中有两个控制器和两个视图。 p>
My 1st 控制器和视图是: p>
1.importController.php,index.ctp;
code> pre>
我的第二个控制器 和视图是: p>
2.titlesController.php,success.ctp;
code> pre>
现在我要发送 从importController.php到success.ctp视图的变量值(例如$ data = 5)。 p>
div>
答
First Redirect
$this->redirect(['controller'=>'titlesController', 'action'=>'success', $variableValue]);//$variableValue any value you can send.
In titlesController
function success($data){
$this->set('data',$data);
}
On success.ctp you can use $data