google-maps - 将 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); ?>
谢谢多姆
解决方案
推荐阅读
- ruby-on-rails - 我正在尝试在 nodejs 中使用纱线包管理器在 ruby-on-rails 中使用 apidoc?拥有操作系统 Ubuntu
- dictionary - 我需要创建一个 YAML 代码来为 windows 分区和格式化磁盘,输入将是一个动态 /json 文件,包含磁盘名称、标签的详细信息
- mongodb - 在 Kotlin 的 vert.x verticle 中创建和访问 MongoDB 数据库
- javascript - neo4j 为 JavaScript 提供的示例脚本不会运行
- android - 无法找到 adb - 使用颤振安装的 android studio
- android - 如何修复找不到类的定义:'android.content.Context'。检查你的定义!在 KoinTest
- python - 使用 for 循环重命名 Pandas 中的列
- scala - 如何将一个正则表达式文字扩展为多行?
- python - 如何修改对数刻度的 xtick 频率?
- java - Oracle 中的 CallableStatement 是如何工作的?