I ein neues Modul geschaffen, in dem ich einen Block durch das folgende Verfahren in IndexController.php
am schaffen, diemagento Fehler einen Block zu schaffen
class Ashfame_Helloblock_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
// this works fine
$block = new Ashfame_Helloblock_Block_Helloblock();
echo $block->toHtml();
}
public function layoutAction() {
// this doesn't work
$layout = Mage::getSingleton('core/layout');
$block = $layout->createBlock('ashfame_helloblock/helloblock','root');
var_dump($block); // this returns false
echo $block->toHtml();
}
}
My Block Klasse an app/code/local/Ashfame/Helloblock/controllers/IndexController.php
ist Ashfame_Helloblock_Block_Helloblock
und ist an app/code/local/Ashfame/Helloblock/Block/Helloblock.php
Da die $block
in layoutAction()
falsch ist, wirft PHP einen Fehler Call to a member function toHtml() on a non-object
auf Debuggen fand ich, dass die magento heraus Bezifferung der Klassenname ist falsch. Es herauszufinden, der Klassenname als mage_Ashfame_helloblock_block
innerhalb getGroupedClassName()
.
Was ist hier falsch?
Was ist Ihre app/code/local/Ashfame/Helloblock/etc/config.xml aussehen? – nachito
Guter Job-Tracing durch die Klassennamenzuordnung. Das Entdeckerherz ist in der Magento-Entwicklung so wichtig. – benmarks
@benmarks heh danke! Ich zweite das :) – Ashfame