in Magento

Fatal error: Call to a member function getHelperClassName() on a non-object

The Problem:

I’m writing a Magento script to display categories in a custom navigation and was getting this error:

Fatal error: Call to a member function getHelperClassName() on a non-object in /var/www/vhosts/dev-site/public_html/app/Mage.php on line 546

 

The Solution:

Mage:app();

 

My Code:

<?php

ini_set('display_errors', '1');
error_reporting(E_ALL);

// include the Magento goodness
require '../app/Mage.php';

Mage::app();

$id = 4; //  category id for this test
?>

<?php $helper = Mage::helper('catalog/category') ?>
<?php $categories = $helper->getStoreCategories() ?>
<?php if (count($categories) > 0): ?>
    <ul class="top-level-category">
        <?php foreach($categories as $category): ?>
            <li>
                <a href="<?php echo $helper->getCategoryUrl($category) ?>">
                    <?php echo $category->getName() ?>
                </a>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>