7

根据此示例,如何将我的变量从 joomla 子控制器传递到视图

    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();
    }
    }
4

1 回答 1

11

在控制器中:

$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;
    //...
  }
}
于 2013-04-15T13:54:04.953 回答