如何将变量从控制器传递到视图 joomla mvc [英] How to pass variable from controller to the view joomla mvc
本文介绍了如何将变量从控制器传递到视图 joomla mvc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何根据本示例将我的变量从 joomla 子控制器传递到视图
How do I pass my variable from joomla sub-controller to the view according to this example
class MYControllerControllerParser extends JController{
public function __construct($default = array()) {
parent::__construct($default);
}
protected function _import($file, $type) {
$layout = '';
switch ($type) {
case 'importcsv':
$contains_headers = false;
$field_separator = JRequest::getVar('separator');
$field_separator = empty($field_separator) ? ',' : $field_separator;
$field_enclosure = JRequest::getVar('enclosure');;
$field_enclosure = empty($field_enclosure) ? '"' : $field_enclosure;
//this variable should be passed to the view
$this->info = $this->getImportInfoCSV($file, contains_headers, $field_separator, $field_enclosure);
//This variable should go to view
$this->file = basename($file);
$layout = 'importcsv';
break;
}
$this->getView('import','html')->display();
}
}
推荐答案
在控制器中:
$view = $this->getView('import','html');
$view->myVariable = 'hello';
$view->display();
在视图中:
class MycomponentViewItem extends JViewLegacy
{
/** @var string my variable */
public $myVariable;
public function display($tpl = null)
{
$myVariable = $this->myVariable;
//...
}
}
这篇关于如何将变量从控制器传递到视图 joomla mvc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文