Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8614437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:07:16+00:00 2026-06-12T05:07:16+00:00

I want to test a Magento block function. I don’t know, how to call

  • 0

I want to test a Magento block function. I don’t know, how to call the function outside .phtml files. Does anybody know a function like getModel() for blocks?

I found

getBlockSingleton()

But, it is deprecated and I can’t get it to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:07:17+00:00Added an answer on June 12, 2026 at 5:07 am

    Let’s say your Magento root is your web root. In your Magento root, create a test.php file. You’ll be able to access it at http://base_url/test.php.

    ini_set('display_errors',true); //PHP has such friendly errors, show them!
    
    include 'app/Mage.php';         //include the helper class/bootstrap file
    Mage::setIsDeveloperMode(true); //flag to render Magento's traces
    
    Mage::app();
    /**
       Instantiate the app. Note that this is different from Mage::run()! This can
       be skipped given the Mage::app() call below.
    */
    
    //block "type"
    $class = 'core/bar';
    
    //block instance
    $block = Mage::app()->getLayout()->createBlock($class);
    
    if (is_object($block)) die("Okay! ".get_class($block));
    
    /**
     * If script execution reaches this point, there is one of
     * two problems:
     *
     * 1) bad/missing config
     * 2) bad path based on filename
     */
    
    //the xpath which is used
    $xpath = 'global/blocks/'.strstr($class,'/',true).'/class';
    
    //a node from config XML (we hope)
    $node = Mage::getConfig()->getNode($xpath);
    
    //error condition 1:
    if (!$node) die("Bad xpath, check configuration: ".$xpath);
    
    //error condition 2:
    $name = uc_words((string) $node . '_' . substr(strrchr($class, '/'), 1));
    $file = str_replace('_', DIRECTORY_SEPARATOR, $name.'.php');
    $issue = '<br /><br />';
    
    if (!is_readable($file)) {
        //no file matching classname
        $issue .= "No file found for $file, tried:<pre> - ";
        $issue .= str_replace(PATH_SEPARATOR,'/'.$file.'<br /> - ',get_include_path()).$xpath.'</pre>';
    } else {
        $issue .= "Wrong class name in $file";
    }
    
    echo sprintf('Xpath ok, looking for class <span style="font-family: Courier New">%s</span>%s',$name,$issue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to test the block function and the value for the context. The
I`m using Magento 1.3 and I want to test the new 1.4, but is
We want to test email functionality on our staging server, but we don't want
I want to test the functionality of my app and would like to automate
I am new to magento. I needed to know if its possible to call
I want to declare some php functions and i would like to call those
I want test a FIX gateway for our company and was wondering if anything
I want to test the login() action in my UsersController.php <?php class UsersController extends
I want to test it on a tablet because it is more natural to
I want to test Add new item activity in my application. When user fills

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.