开发者

Magento is not recognising variables ($variable $_variable)

I'm migrating a machine to my local server and there is something weird with the variables and other functions. For example, Magento shows this error:

Notice: Undefined variable: key  in [...]template/catalog/product/view/attributes.phtml

If I go to that function, I see this:

<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
 <?php echo $key; if ($_order != 'Relevancia') : // Remove "Relevancia" from the sort optio开发者_运维知识库n list ?>
  <option value="<?php echo $_key; // echo $this->getOrderUrl($_key, 'asc') ?>"<?php    if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
   <?php echo $this->__($_order) ?>
  </option>
 <?php endif; ?>
<?php endforeach; ?>

It seems that magento can't recognise the «$key» as a «$_key», and this happens in the whole code. The thing is that this code is working in the production server so... I'm missing something, and I don't know what it is.

Thanks for your help!


PHP is complaining because you haven't defined the variable $key in the code snippet.

<?php echo $key;

The variable $key is distinct from the variable $_key

The PHP error level here is Notice. A notice is the lowest PHP error level, and it's usually possible to continue execution after a notice has been issued.

My guess is your production server is configured to not display error

ini_set('display_errors', 0);

And the developer mode constant set to false

$_SERVER['MAGE_IS_DEVELOPER_MODE']

This allows Magento to continue past the notice. If you check your logs, it's probably still being issued. On your local machine, with display errors on your see the Notice in your browser. With developer mode on Magento will throw an exception for any simple error.

It's also possible that prior to your code block, there's something conditionally defining $key base on database state, and it happens in production, but not with your dev configuration/database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜