[英]Joomla Component MVC variable passing between View and Controller
對於Joomla以及它們實現MVC體系結構的方式,我才是新手。 它與我的習慣(代碼點火器等)略有不同,並且我在將數據傳遞到視圖時遇到了一些問題。
我在控制器中創建了一個名為“ getInitClubs”的函數,該函數將在頁面運行時自動運行,因此,我已從“ view.html”文件中對該函數進行了調用。
這是我的代碼:
控制器功能:
public function getInitClubs() {
$model =& $this->getModel('directory');
$init_clubs = $model->clubResults($conds = array());
return $init_clubs;
}
型號功能:
public function clubResults($conds) {
$query = "SELECT * FROM vyj20_contact_details";
if(isset($conds['city'])) {
$query .= " WHERE state = '" . mysql_escape_string($conds['city']) . "'";
}
if(isset($conds['suburb'])) {
$query .= " AND suburb = '" . mysql_escape_string($conds['suburb']) . "'";
}
$this->_db->setQuery($query);
$results = $this->_db->loadObjectList();
return $results;
}
現在我知道模型和控制器代碼有效,這不是問題,問題實際上是從控制器函數“ getInitClubs”中提取結果並通過視圖顯示它們。
我如何從視圖中調用控制器函數(就像在Code Igniter MVC上那樣)以收集顯示的結果? 我已經嘗試了很多,但似乎無法弄清楚! 謝謝
您的控制器功能應該是這樣的。
$model =& $this->getModel('directory');
$init_clubs = $model->clubResults($conds = array());
$view = $this->getView('view_name', 'html'); // get the view
$view->assignRef('data_list', $init_clubs); // set the data to the view
$view->display(); // show the view
閱讀更多
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.