views:

80

answers:

2

I've create a custom admin module but i can't put a content in it, it always is blank i'm trying with a simple code for test, but nothing seem to work

public function indexAction()
{
    $this->loadLayout();

    $this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('uhmaadmin/contactos.list.phtml')->toHtml());
    $this->renderLayout();
}

an in the .phtml

echo 'hello world';

but doesn't print nothing, if a make an error in the phtml, the system crash, it means that its getting the file, but, what i'm i missing please, help

+2  A: 

The $this->_addContent method on an admin controller expects to be passed a block object.

protected function _addContent(Mage_Core_Block_Abstract $block)
{
    $this->getLayout()->getBlock('content')->append($block);
    return $this;
}

You're passing in

$this->getLayout()->createBlock('adminhtml/template')->setTemplate('uhmaadmin/contactos.list.phtml')->toHtml()

which is a string. You're rendering it too soon. If you check your logs you should see a warning/error/something telling you that the argument to _addContent is an unexpected type.

Try it without the toHtml method call

$this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('uhmaadmin/contactos.list.phtml'));
Alan Storm
Thanks, it works, you save my day, i can't vote cuz i can register and i don'tknow why, i always get en error in the last step, i will give you a 10...thanks again, but now now i'm getting Call to a member function setTemplate() on a non-object error, cuz i'm calling createBlock('uhmaadmin/template'), my Template look like thisclass Uhma_UhmaAdmin_Block_Template extends Mage_Core_Block_Template{}is something wrong with my code?
Kstro21
A: 

Thanks, it works, you save my day, i can't vote cuz i can register and i don'tknow why, i always get en error in the last step, i will give you a 10...thanks again, but now now i'm getting Call to a member function setTemplate() on a non-object error, cuz i'm calling createBlock('uhmaadmin/template'), my Template look like this

class Uhma_UhmaAdmin_Block_Template extends Mage_Core_Block_Template
{

}

is something wrong with my code?

Kstro21