偏移'我得到一個Warning: Illegal string offset 'customitem_id' in admin/controller/sale/customer.php
警告:非法串在
和/admin/controller/sale/customer.php on line 941Notice: Uninitialized string offset: 0
我想顯示所有相關的定製產品列表中,我不知道這個錯誤是什麼意思。這裏是代碼,它工作,如果我沒有foreach循環,但只有一個產品正在顯示。我需要其他5個指定產品也顯示出來。
`//自定義項分配給客戶
if (isset($this->request->post['customitem_id'])) {
$data['customitem_id'] = $this->request->post['customitem_id'];
} elseif (!empty($customer_info)) {
$data['customitem_id'] = $customer_info['customitem_id'];
} else {
$data['customitem_id'] = 0;
}
$data['product_relateds'] = array();
if(isset($data['customitem_id'])) {
$related_infos = $this->model_sale_customer->getProduct($data['customitem_id']);
foreach($related_infos as $related_info) {
$data['product_relateds'][] = array(
'customitem_id' => $related_info['customitem_id'],
'name' => $related_info['name']
);
}
}
任何幫助,將不勝感激。
在TPL文件中的其他代碼看起來像這樣
$('input[name=\'related\']').autocomplete({ 'source': function(request, response) { $.ajax({ url: 'index.php?route=catalog/customitems/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent(request), dataType: 'json',
success: function(json) { response($.map(json, function(item) { return { label: item['name'], value: item['customitem_id'] } })); } }); }, 'select': function(item) { $('input[name=\'related\']').val('');
$('#product-related' + item['value']).remove();
$('#product-related').append('<div id="product-related' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="customitem_id[]" value="' + item['value'] + '" /></div>')`
和
<div class="form-group"> <label class="col-sm-2 control-label" for="input-related"><span data-toggle="tooltip" title="<?php echo $help_related; ?>"><?php echo $entry_addcustomitem; ?></span></label> <div class="col-sm-10"> <input type="text" name="related" value="" placeholder="<?php echo $entry_addcustomitem; ?>" id="input-related" class="form-control" /> <div id="product-related" class="well well-sm" style="height: 150px; overflow: auto;"> <?php foreach ($product_relateds as $product_related) { ?> <div id="product-related<?php echo $product_related['customitem_id']; ?>"><i class="fa fa-minus-circle"></i> <?php echo $product_related['name']; ?> <input type="hidden" name="customitem_id[]" value="<?php echo $product_related['customitem_id']; ?>" /> </div> <?php } ?> </div> </div> </div>
此代碼不會導致此類錯誤。您必須顯示錯誤發生的行號 – Croll
錯誤行是942行941警告:非法字符串偏移'名稱'在'和'在線942警告:非法字符串偏移'customitem_id'' –
增加了額外的代碼原問題 –