0

このエラーがあります:

[2012年7月25日水曜日15:48:09][エラー][クライアント50.xxx.xxx.xxx]PHP致命的なエラー:/ var / www / magento / app内の非オブジェクトでメンバー関数getSource()を呼び出す/code/core/Mage/Catalog/Model/Product.php(1389行目)

この関数では:

/**
 * Get attribute text by its code
 *
 * @param $attributeCode Code of the attribute
 * @return string
 */
public function getAttributeText($attributeCode)
{
    return $this->getResource()
       ->getAttribute($attributeCode)
            ->getSource()
                ->getOptionText($this->getData($attributeCode));
}

そして、エラーが発生するたびに$attributeCode値をログに記録したいと思います。だから私はこれに関数を変更します:

public function getAttributeText($attributeCode)
{
    try {
        return $this->getResource()
           ->getAttribute($attributeCode)
                ->getSource()
                    ->getOptionText($this->getData($attributeCode));
    } catch (Exception $e) {
        Mage::log($attributeCode);
        throw($e);
    }
}

…そしてApacheを再起動しますが、server.logには何も表示されません。throw($ e)をコメントアウトしても、例外はスローされます。

./lib/Zend/Rest/Server.phpにはset_exception_handler(array($ this、 "fault"));があります。

ただし、どこかに設定すると、phpはすべての手動例外処理を無視しないことを教えてください。それはおかしいからです。

例外が発生した場合にのみ$attributeCodeをキャプチャする方法はありますか?

4

2 に答える 2

1

試す

$attributes = $this->getResource()->getAttribute($attributeCode);
if (!empty($attributes)) {
    return $attributes->getSource()->getOptionText($this->getData($attributeCode));
} else {
    Mage::log($attributeCode);
    throw new InvalidArgumentException('bla bla');
}

// getAttribute($ attributeCode);によって何が返されるかわかりません したがって、empty()の代わりに、is_null()、isset()を使用できます。

于 2012-07-26T22:45:17.803 に答える
0

デバッグの目的でのみ、これを行います。

if (!is_object($this->getResource()->getAttribute($attributeCode)) {
    var_dump($attributeCode);
    exit();
}
于 2012-07-26T21:48:05.067 に答える