0
如何從joomlas佈局調用模型方法來收集數據? 我嘗試使用谷歌地圖經緯度和搜索我得到檢索一個對象它包含指定的數據,並從佈局我會初始化數據以獲得所需的XML如下。我知道不是最好的解決方法,但我不想兩次執行相同的查詢。如何從joomla佈局中調用模型傳遞對象
控制器調用模型
$model = $this->getModel('item');
$view = $this->getView('item', 'html'); // get the view
$view->setLayout('default:items');
$view->assignRef('url_var', $this->input->get('state'));
$view->assignRef('city', $this->input->get('city'));
view.html
function display($tpl = null)
{
// Assign data to the view
$this->item_list = $this->get(Items, $this->city);
$this->xml_map = $this->get(createMapXML, $this->item_list);
//Here I do not get back the queries Object list.Shows me the passed ID what I want to pass to model as argument
var_dump($this->get(Items, $this->city));
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');
return false;
}
// Display the view
parent::display($tpl);
}
var mark;
var pointA;
if (GBrowserIsCompatible()) {
var m = jQuery("#map")[0];
if(m) {
var map = new GMap2(m);
var start = new GLatLng(63.13450320833446,16.69921875);
var zoomLevel = 5;
map.setCenter(start, zoomLevel);
map.addControl(new GSmallMapControl());
//here I would create the xml calling model function
jQuery.get('<?php //$model->createMapXML($this->items)?>',function(data) {
jQuery(data).find('marker').each(function(){
var lat = jQuery(this).attr('lat');
var lng = jQuery(this).attr('lng');
var html = jQuery(this).attr('name')+" ";
html += jQuery(this).attr('msg')+" ";
html += jQuery(this).attr('link');
var point = new GLatLng(lat,lng);
var marker = new GMarker(point);
map.addOverlay(marker);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
});
});
GEvent.addListener(map, 'click', function(overlay, point){
if(mark) {
map.removeOverlay(mark);
}
if(point) {
pointA = new GPoint(point.x, point.y);
mark = new GMarker(pointA);
map.addOverlay(mark);
map.getCenter(point);
var lat = point.y;
var lng = point.x;
map.openInfoWindowHtml(point,form);
}
});
}
}
謝謝,是的,你幫助我找到正確的方向,只是我不明白的一件事,如何從view.html中調用模型。我延長我的代碼,也許你可以幫助更多。先謝謝了!! – deroccha 2013-05-03 11:00:43
再次感謝您的幫助 – deroccha 2013-05-03 11:08:47
$ model = $ this-> getModel('profile','UsersModel');這將加載配置文件模型 – 2013-05-03 11:14:38