【问题标题】:Magento can't debug install scriptMagento 无法调试安装脚本
【发布时间】:2015-04-01 06:01:51
【问题描述】:

我正在尝试不费吹灰之力地调试我的安装脚本。 当我尝试在我的 foreach 循环中获取任何输出时,我的 Mage::Log() 文件中没有结果。

<?php
$installer = $this;
$installer->startSetup();
$attrCodes = ['attr1', 'attr2', 'attr3'];
$objCatalogEavSetup = Mage::getResourceModel('catalog/eav_mysql4_setup', 'core_setup');

Mage::log('hello before foreach');
// get all attributes
foreach ($attrCodes as $attrCode) {
  Mage::log('Attribute code: ' . $attrCode);
}

Mage::log('hello after foreach');
$installer->endSetup();

我可以在 foreach 循环之前看到日志信息。 但我在那个循环内部或之后没有得到任何信息。

不能调试安装脚本吗? 我通常使用 PHPStorm 并使用内部调试器。 但似乎我无法使用 PHPStorm 或 Mage::Log() 调试安装脚本。

编辑:
对于这个混乱,我深表歉意。
我没有将功劳归功于循环上方的注释行,所以我决定在这里缩短我的代码。
但事实是我不能用一行注释来调用我的升级脚本。
这就是我的问题的原因。 我必须将行注释更改为块注释 /**/ 现在它可以工作了。

以前从未遇到过使用 magento 的这个问题。

【问题讨论】:

  • 你说你可以在 foreach 之前看到日志,但更重要的是,你看到 after foreach 的信息了吗?如果没有,则意味着您必须在 foreach 中 in 出错。

标签: php magento debugging logging mage


【解决方案1】:

同意,使用“Tipo”,问题出在 foreach 循环中。 您应该在创建数组时尝试此编辑:

$attrCodes = array('attr1', 'attr2', 'attr3');

【讨论】:

  • 我不这么认为。如果他的服务器无法识别新数组 [] 表示法,则 OP 将在第一个 Mage::log之前出现错误
  • 如果没有被识别,那么他只会得到一个警告或通知,而不是错误,但是如果他将一个变量传递给 foreach 不是数组的东西,他会得到一个错误......
  • 嗯,刚刚测试,你是完全正确的。我从解析器中排除了 unexpected [ 之类的内容。
【解决方案2】:

试用此代码并检查

$attrCodes = array('attr1', 'attr2', 'attr3');
Mage::log('hello before foreach');
foreach ($attrCodes as $attrCode) {
    Mage::log('Attribute code: ' . $attrCode);
}
Mage::log('hello after foreach');

【讨论】:

    猜你喜欢
    • 2014-08-26
    • 1970-01-01
    • 1970-01-01
    • 2020-05-02
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多