我想在注册帐户步骤中将地理区域显示为下拉菜单,就像区域(区域)一样。但是地理区域的价值取决于客户在区域(区域)中选择的内容。
图片
在这个过程中,我已经对控制器、视图、包括控制器做了一些修改。就像在下面的图片中一样:
地理区域场是 Kotamadya/Kabupaten。但是当我选择区域 Aceh 时,geozone 字段不会刷新。
错误信息
我收到如下错误消息:
SyntaxError: Unexpected token <
OK
<br />
<b>Fatal error</b>: Call to a member function
getGeozonesByZoneId() on a non-object in <b>
/home/........../catalog/controller/account/register.php
</b> on line <b>513</b><br />
编码
在 ../controller/account/register.php 中,我添加了一些修改如下:
public function zone() {
$json = array();
$this->load->model('localisation/zone');
$geozone_info = $this->model_localisation_zone->getZone($this->request->get['zone_id']);
if($geozone_info)
{
$this->load->model('localisation/geo_zone');
$json = array(
'country_id' => $geozone_info['country_id'],
'name' => $geozone_info['name'],
'code' => $geozone_info['code'],
'zone' => $geozone_info['zone_id'],
'geozone' => $this->model_localisation_geozone->getGeozonesByZoneId($this->request->get['zone_id']),
'status' => $geozone_info['status']
);
}
$this->response->setOutput(json_encode($json));
}
第 513 行是:
'geozone' => $this->model_localisation_geozone->getGeozonesByZoneId($this->request->get['zone_id'])
我不知道 getGeozonesByZoneId 函数有什么问题,因为我认为我已经在 ../model/localisation/geo_zone.php 中正确编写了该函数,如下所示:
<?php
class ModelLocalisationGeozone extends Model {
public function getGeozone($zone_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "geo_zone WHERE geo_zone_id = '" . (int)$geo_zone_id . "'");
return $query->row;
}
public function getGeozonesByZoneId($zone_id) {
$geozone_data = $this->cache->get('geozone.' . (int)$zone_id);
if (!$geozone_data) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE zone_id = '" . (int)$zone_id . "'");
$geozone_data = $query->rows;
$this->cache->set('geozone.' . (int)$zone_id, $geozone_data);
}
return $geozone_data;
}
}
?>
我已经在 register.tpl 中添加了 javascript,如下所示:
$('select[name=\'zone_id\']').bind('change', function(event, first_time) {
$.ajax({
url: 'index.php?route=account/register/zone&zone_id=' + this.value,
dataType: 'json',
beforeSend: function() {
$('select[name=\'zone_id\']').after('<span class="wait"> <img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('.wait').remove();
},
success: function(json) {
var html = '<option value=""><?php echo $text_select; ?></option>';
var selected = false;
if (json['geozone'] && json['geozone'] != '') {
for (i = 0; i < json['geozone'].length; i++) {
html += '<option value="' + json['geozone'][i]['geo_zone_id'] + '"';
if (json['geozone'][i]['geo_zone_id'] == '<?php echo $geo_zone_id; ?>') {
html += ' selected="selected"';
selected = true;
}
html += '>' + json['geozone'][i]['name'] + '</option>';
}
} else {
html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
}
$('select[name=\'geo_zone_id\']').html(html);
if(typeof first_time === "undefined" && selected) {
$("#register_details_form").validate().element('#register_details_form select[name="geo_zone_id"]');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('select[name=\'zone_id\']').trigger('change', ['first_time']);
谁能帮我解决这个问题?或者也许与我有相同的经历并愿意与我分享您的解决方案?
提前谢谢。