Magento Development Environment

焦光霁
2023-12-01

Magento Development Environment

Learning Magento can range from frustrating to infuriating for the first time user. Here’s a few tips to ease the burden of assimilating an entirely new system.

Turn on Logging

While the Magento Community Edition doesn’t have much default logging, it does have a solid logging system in place. Anywhere you can execute PHP in Magento you can do something like

Mage::Log($variable);

Magento will output the contents $variable to a log. Arrays and Objects are auto-expanded and pretty printed, allowing you quickly zoom in on the portion of the data structure you’re interested in. I’ve found using this in combination with Mac OS X’s Console.app to be a much smoother experience than dumping objects to the browser, particularly given how often Magento objects store references to a good portion of the system (resulting is large object data dumps).

Logging is turned off by default, to change that

  1. In the Magento Admin, go to System->Configuration
  2. In the left column, click on Developer (under Advanced)
  3. If it’s not expanded, Click on Log Settings
  4. Select Yes from the “Enabled” drop down
  5. Click on Save Config

Unfortunately, Magento won’t create your log files for you. If they don’t exist you’ll need to create them yourself. By default, log files are stored at

var/log/system.log
var/log/exception.log

If the log folder doesn’t exist, create it along with system.log andexception.log. Make sure Apache has write access to both the directory and the files. Check with your system administrator on the best way to do this.

Calls made using Mage::Log will be dropped in system.log. Exceptions will be logged to exception.log

Turn on Developer Mode

If you look in the Magento bootstrap file (index.php) you’ll see lines similar to the following

#Mage::setIsDeveloperMode(true);
#ini_set('display_errors', 1);

Uncomment these. In a production system, you’d never want to have your errors display to the browser, but while developing having an errors and warnings thrown immediately in your face is invaluable.

Setting the IsDeveloperMode flag is a big time saver. By default, when Magento discovers an exception, it will log the exception to a report and then forward the user to a page that will display that report. This can be infuriating when you’re developing, particularly because Magento redirects in such a way that you can’t backup to the page you were just on. Setting the developer mode flag results in the Exception output being sent directly to the browser with <pre> formatting.

Like this article? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start workingwith Magento instead of against it.

Read more about  Magento
Originally published July 2, 2009

 类似资料:

相关阅读

相关文章

相关问答