【问题标题】:Trying to get property of non-object in Prestashop 1.6.1.11 Webox module试图在 Prestashop 1.6.1.11 Webox 模块中获取非对象的属性
【发布时间】:2017-03-11 12:23:00
【问题描述】:

注意:尝试在第 354 行的 /home/....................../modules/webox/webox.php 中获取非对象的属性

注意:尝试在第 393 行的 /home/......................./webox/webox.php 中获取非对象的属性

警告:在第 393 行的 /home/......................./webox/webox.php 中为 foreach() 提供了无效参数


代码:346-414

346 类 WeboxClass{

347 公共 $total_count = 0;

public $json;
public function __construct($json = "") {
    if(strlen($json) == 0){
        $json = $this->downloadAutomatakAndReturn();
    }
    $this->json = json_decode($json);

354 $this->total_count = $this->json->total_count;}

public function downloadAutomatakAndReturn(){
    $tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : (is_callable('sys_get_temp_dir') ? sys_get_temp_dir() : '');

    if (!is_file($tmp_dir.'/validboltlista.json') || filemtime($tmp_dir.'/validboltlista.json')+86400<time()) {
        $jsonData=file_get_contents('https://api-hu.easypack24.net/v4/machines?type=0');
        file_put_contents($tmp_dir.'/validboltlista.json', $jsonData, LOCK_EX);
}else{
        $jsonData=file_get_contents($tmp_dir.'/validboltlista.json');
    }
    return $jsonData;
}

function getAllAutomataAsOptions($selectedAutomata){
    $result = "";
    $automatak = array();
    foreach($this->getAutomatakByTelepules("") as $automata){
        /* @var $automata WeboxItem */
        $cim = $automata->getAddress_city() . " " . $automata->getAddress_post_code() . ", " . $automata->getAddress_street() . " " . $automata->getAddress_building_no();
        $automatak[$automata->getId()] = array(
            'text' => $cim . " (" . $automata->getId() . ")", 
            'id' => $automata->getId(), 
            'map' => $automata->getMinimap(), 
            'info' => $automata->getLocation_description()
        );
    }
    sort($automatak);
    foreach($automatak as $s){
        $selected = (strlen($selectedAutomata) > 1 && $s['id'] == $selectedAutomata ? "selected='selected'" : "");
        $result .=  "<option value='".$s['id']."' data-map='".$s['map']."' data-info='".$s['info']."' ".$selected.">".$s['text']."</option>\n";
    }
    return $result;

}

function getAutomatakByTelepules($telepules){
    $result = array();

393 foreach($this->json->_embedded->machines as $id => $json){

        if($json->address->city == $telepules || strlen($telepules) == 0){
            $result[$id] = new WeboxItem($json);
        }
    }
    return $result;
}

function getAutomataByID($id){
    foreach($this->json->_embedded->machines as $id => $json){
        if($json->id == $id){
            return @new WeboxItem($json);
        }
    }
    return null;
}

function getTotalCount() {
    return $this->total_count;
}

}

【问题讨论】:

  • 您有问题吗?
  • 对不起,我有一个问题:解决方案是什么?网页前端debub通知: 注意: Trying to get property of non-object in /home/....................../modules/webox/webox.php在第 354 行注意:尝试在第 393 行的 /home/......................./webox/webox.php 中获取非对象的属性警告: 在第 393 行的 /home/......................./webox/webox.php 中为 foreach() 提供的参数无效

标签: php json object


【解决方案1】:

代码是正确的。

问题出在服务器上。我已将 prestashop 安装到另一台服务器并安装了 webbox 插件。有工作。

但问题不在于 php.ini 文件和 htaccess 文件。我已将所有文件从一台服务器复制到另一台服务器,但没有解决问题。

总结:代码是正确的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2014-12-09
    相关资源
    最近更新 更多