2013-04-15 34 views
6

Làm thế nào để vượt qua biến tôi từ joomla phụ điều khiển để nhìn theo ví dụ nàyLàm thế nào để vượt qua biến từ bộ điều khiển để quan điểm joomla MVC

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

Trả lời

10

Trong Bộ điều khiển:

$view = $this->getView('import','html'); 
$view->myVariable = 'hello'; 
$view->display(); 

Trong Xem:

class MycomponentViewItem extends JViewLegacy 
{ 
    /** @var string my variable */ 
    public $myVariable; 

    public function display($tpl = null) 
    { 
    $myVariable = $this->myVariable; 
    //... 
    } 
} 
+0

Cảm ơn rất nhiều đang làm việc !! – fefe

+0

@pirtr_cz cách sử dụng $ myVariable này trong bố cục? –

+1

@Harsimran> thử '$ this-> myVariable' do bố cục là một phần của chế độ xem –

Các vấn đề liên quan