Use
Mage::helper('catalog/image')
instead of
$this->helper('catalog/image')
Additional points
In order to work this, you need to make sure app/Mage.php
is included in your custom php file. You have specified your php file stays in root directory folder. In that case you need to include these codes first in your custom php file.
/**
* Error reporting
*/
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
require_once 'app/Mage.php';
Mage.php
is a final
class. Hence it cannot extend. This file holds lot of useful common methods. Such a method is helper
.
We can use Mage::helper
everywhere in Magento, since helper classes are globally available all over Magento.
Generally helper classes are accessed like this
Mage::helper('helper_alias/classname');
Here helper_alias
is used to find which module's helper should use. In our example, it is catalog
. This means Magento should use Mage_Catalog_Helper
directory for find helper class. classname
stands of which helper class should use. If it is not sepcified, by default magento use Data
class. In example, classname
is specified as image
. This means Magento will finally use class Mage_Catalog_Helper_Image
class for it.
All helper classes are globally available. This means we can use them almost everywhere in magento. This is because, Magento will "register" helper classes using the method Mage::register
. This particular method is use to make something globally available. When we think about this, it is highly logical, since a "help" should be available everywherer :-) So if we make helpers only available to the defined module, then that is not good. The point is all helpers of every module should be globally accessible so that we can use any one of module's help at any time.
Since helpers are globally available, they add lot of advantages and similarly disadvantages. Always try to put useful common methods in helper.