如何在CakePHP中通过操作将变量设置为其他ctp文件?
我使用的是CakePHP3。我的行动是:如何在CakePHP中通过操作将变量设置为其他ctp文件?,cakephp,cakephp-3.0,Cakephp,Cakephp 3.0,我使用的是CakePHP3。我的行动是: function OrderFromReseller($api_key) { $this->render('index'); $this->loadModel('Psetting'); $products = $this->Psetting->find('all'); $this->set(compact('products')); } 这里我呈现另一个名为index.ctp的ctp文件。现
function OrderFromReseller($api_key) {
$this->render('index');
$this->loadModel('Psetting');
$products = $this->Psetting->find('all');
$this->set(compact('products'));
}
这里我呈现另一个名为index.ctp的ctp文件。现在“products”变量在索引中未定义。如何通过此操作将此变量设置为index.ctp文件 您需要调用
$this->render('index')
最后:-
function OrderFromReseller($api_key) {
$this->loadModel('Psetting');
$products = $this->Psetting->find('all');
$this->set(compact('products'));
$this->render('index');
}
render()
告诉Cake生成视图,这样模板就不会考虑下面的任何内容,因为它已经被渲染了。您需要调用$this->render('index')
最后:-
function OrderFromReseller($api_key) {
$this->loadModel('Psetting');
$products = $this->Psetting->find('all');
$this->set(compact('products'));
$this->render('index');
}
render()
告诉Cake生成视图,这样模板就不会考虑下面的内容,因为它已经被渲染了