I have two simple method inside controller

public indexAction 
public TestAction{

echo "Kkkdfd"

I have a template named something.phtml How do i call testaction from my template to display php echo?

2 Answers 2


You don't, controllers aren't meant for that. You can call module/controller/action as url to display the echo. If you want to use a custom method to handle some logic in your template use blocks instead.

Edit: I can't help you with the library, but to finish up this answer I give you an example to create a custom block.

Create a new module in `app/etc/modules/Your_Module.xml

<?xml version="1.0"?>

Create a module config app/code/local/Your/Module/etc/config.xml

<?xml version="1.0"?>

The global/blocks part defines your Block Prefix, which you can use to call it in your layout.

Create the block now in app/code/local/Your/Module/Block/Block.php

class Your_Module_Block_Block extends Mage_Core_Block_Template
    public function yourLogic() 
        //your code here

Now all you have to do is change your layout block to use the new custom block. Do it like this:

<block type="your_module/block" name="yourblock" template="your/template.phtml" />

The type refers to your config.xml and block file. The your_module part is the block prefix, so Your_Module_Block, and the second block part refers to the Block.php file.

In your template you can make a direct call to $this->yourLogic() now.

Hope this helps your sort things out.

  • Can you elaborate on how to use block to load those? thanks
    – beginner
    Mar 31, 2015 at 5:33
  • What are you trying to achieve? Are you just using some custom template or do you want to modify an existing one? The difference is a new block or overriding an existing one, which both work a bit differently. Mar 31, 2015 at 5:43
  • its custom template. Actually i am trying to get third party php library to work but i cant seem to get to autoloader. so i decided to use template to call the controller for event and then make an observer to autoload the lib. if you have any idea about abrahim/twitterauto, please let me know.
    – beginner
    Mar 31, 2015 at 5:51
  • See my edited answer. Hope this helps. Mar 31, 2015 at 6:39

from your comments I read that your actual problem is that the library is not loaded.

The easiest way would be to install it with composer and use magento module that includes the composer autoloader.

If you don't know how to install / use composer, you should start here: https://getcomposer.org/doc/00-intro.md

once composer is working you can install your library with the following command:

composer require abrahim/twitterauto

The Problem now is, that Magento does not include the Composer Autoloader, but there is a Module for this: https://github.com/magento-hackathon/Magento-PSR-0-Autoloader

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.