首页 > 解决方案 > 将 PHP 中的 Google 地图复制到新页面

问题描述

帮助将一些现有的“工作”代码复制到具有相似但略有不同的调用的新页面。

现有models/project.php代码如下;

    function getDetailProject(){
    $app    = JFactory::getApplication();
    $db = JFactory::getDbo();
    $user   = JFactory::getUser();
    $id     = $app->input->get('id', 0, 'int');

    $config = JblanceHelper::getConfig();
    $sealProjectBids = $config->sealProjectBids;

    $row = JTable::getInstance('project', 'Table');
    $row->load($id);

    //get the location info
    $location  = JTable::getInstance('location', 'Table');
    if($row->id_location > 0){
        $location->load($row->id_location);
        $this->setState('projectLocation', $location->params);
    }

php模板代码如下;

              <div class="control-group">
<label class="control-label nopadding"><?php echo JText::_('COM_JBLANCE_LOCATION'); ?>:</label>
<div class="controls">
  <?php echo JblanceHelper::getLocationNames($row->id_location); ?>
  </div>
  </div>
    </div>
  <br>
        <?php 
        //show map if the id_location is > 0
        if($row->id_location > 0){
            $location = new JRegistry;
            $location->loadString($this->get('State')->get('projectLocation'));
            $lat =  $location->get('latitude');
            $long = $location->get('longitude');
            if(!(empty($lat) && empty($long))){ 
                JblanceHelper::getGoogleMap($lat, $long, $row->project_title);
                ?>
                <div class="img-polaroid">
                    <div id="map-canvas" style="width: 100%; height: 300px;"></div>
                </div>
            <?php   
            }
            else { ?>

            <?php   
            }
        }
         ?>

现在新代码(我不确定我是否缺少另一个支持文件?)试图让地图与用户的位置而不是项目一起工作?

模型/user.php

    function getViewProfile(){

    $app    = JFactory::getApplication();
    $db     = JFactory::getDbo();
    $user   = JFactory::getUser();
    $userid = $app->input->get('id', $user->id, 'int');     //get the user id from 'get' variable; else default is current user id

    //$jbuser = JblanceHelper::get('helper.user');      // create an instance of the class UserHelper -ADDED BY DOM-
    //$userInfo = $jbuser->getUserGroupInfo($userid, null);         // this holds the info of profile owner -ADDED BY DOM-
    $row = JTable::getInstance('jbuser', 'Table');
    $row->load($id);

    //get the location info -ADDED BY DOM-
    $location  = JTable::getInstance('location', 'Table');
    if($row->id_location > 0){
        $location->load($row->id_location);
        $this->setState('userLocation', $location->params);
    } 

和php页面

            <div class="control-group">
<label class="control-label nopadding"><?php echo JText::_('COM_JBLANCE_LOCATION'); ?>:</label>
<div class="controls">
  <?php echo JblanceHelper::getLocationNames($row->id_location); ?>
  </div>
  </div>
        <?php 
        //show map if the id_location is > 0
        if($row->id_location > 0){
            $location = new JRegistry;
            $location->loadString($this->get('State')->get('userLocation'));
            $lat =  $location->get('latitude');
            $long = $location->get('longitude');
            if(!(empty($lat) && empty($long))){ 
                JblanceHelper::getGoogleMap($lat, $long, $row->biz_name);
                ?>
                <div class="img-polaroid">
                    <div id="map-canvas" style="width: 100%; height: 300px;"></div>
                </div>
            <?php   
            }
            else { ?>

            <?php   
            }
        }
         ?>

对我可能错过的无意复制代码有什么帮助吗?

我认为答案可能与 $row 有关?

此代码返回“viewprofile.php”中的位置

<?php echo JblanceHelper::getLocationNames($this->userInfo->id_location); ?>

但是此代码不返回位置

<?php echo JblanceHelper::getLocationNames($row->id_location); ?>

谢谢多姆

标签: google-mapsjoomla3.0

解决方案


推荐阅读