簡體   English   中英

警告:輸入中的字符串偏移量''

[英]Warning: Illegal string offset ' ' in

我收到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>

當所討論的變量是字符串而不是數組時,將引發錯誤。 在這種情況下$related_info $related_infovar_dump可以提供幫助。

您的第一個錯誤“ admin / controller / sale / customer.php中的非法字符串偏移'customitem_id'”很可能是您的變量不是數組而是一個字符串。

您的第二個錯誤“通知:未初始化的字符串偏移量:0”指示變量是數組,但索引為0,則變量是字符串,但為空

下面的簡單測試注釋和取消注釋每個錯誤:

$ dummyVar =“你好”;

//錯誤=>未初始化的字符串偏移量:5 //回顯$ dummyVar [5];

//錯誤=>非法的字符串偏移量'key-name'// echo $ dummyVar ['key-name'];

//錯誤=>未定義索引:鍵名$ dummyVar2 = array(); $ dummyVar2 [0] ='東西'; // echo $ dummyVar2 ['key-name'];

//錯誤=>未初始化的字符串偏移量:0 $ emptyString =''; echo $ emptyString [0];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM