0

joomlasレイアウトからモデルメソッドを呼び出してデータを収集するにはどうすればよいですか? 緯度と経度でGoogleマップを使用しようとすると、検索時に指定されたデータが含まれているオブジェクトを取得し、レイアウトからデータを初期化して、次のように目的のxmlを取得します。最善の回避策ではないことはわかっていますが、同じクエリを 2 回実行したくありません。

コントローラー呼び出しモデル

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

1 に答える 1

0

レイアウトは view.html.php を介してロードされます。したがって、モデルはView.html.phpに含まれています。つまり、レイアウト内で次のようなモデル関数にアクセスできますClassName :: FunctionName();

別のオプションは、view.html.php のモデルを次のような変数に割り当てることです。

$this->assignRef("product_model",$model);

次に、レイアウトでアクセスできます

$this->product_model->function();

これがあなたを助けることを願っています。

于 2013-05-03T10:41:43.960 に答える