dqnf28092 2016-09-29 03:56
浏览 16
已采纳

产品货币无法正常工作,我在Modx系统中收到错误[关闭]

I have use Modx CMS. today i get this error. Bellow my error line.

Fatal error: Call to a member function get() on null in /var/www/bottega/core/cache/includes/elements/modsnippet/63.include.cache.php on line 24

$id = $row['id'];
$product = $modx->getObject('modResource',  $id)->Product;
$price = $product->sm_price;
$currency = (int)$product->sm_currency; //$currency out is 153 dynamically
$currency =  $modx->getObject('modResource', trim($currency))->get('longtitle'); //this line number 24

Actually, when i initialize manually $currency variable 153 then this problem solve. but when i use $currency initialize from database (int)$product->sm_currency; it show error

Fatal error: Call to a member function get() on null in /var/www/bottega/core/cache/includes/elements/modsnippet/63.include.cache.php on line 24

For example $currency variable manually initialize with 153

$id = $row['id'];
$product = $modx->getObject('modResource',  $id)->Product;
$price = $product->sm_price;
$currency = 153; 
$currency =  $modx->getObject('modResource', trim($currency))->get('longtitle'); //this line number 24

Now work fine

  • 写回答

1条回答 默认 最新

  • douzangdang2225 2016-09-29 06:09
    关注

    This could be caused by a change of the PHP version by your hosting company.

    Since you added some code in your question: Please check whether an object exist, before you use it (sample below).

    $id = $row['id'];
    $productRes = $modx->getObject('modResource',  $id);
    if ($productRes && $productRes->Product) {
        $product = $productRes->Product;
        $price = $product->sm_price;
        $currency = (int)$product->sm_currency;
        $currencyRes = $modx->getObject('modResource', $currency);
        if ($currencyRes) {
            $currency = currencyRes->get('longtitle');
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退