I have created a custom block and when I try to access a method from my block I get:
exception 'Exception' with message 'Notice: Undefined variable: this in /Applications/XAMPP/xamppfiles/htdocs/mag19/app/design/frontend/vish/default/template/Vish/sizecheck/sizecheck.phtml on line 2' in /Applications/XAMPP/xamppfiles/htdocs/mag19/app/code/core/Mage/Core/functions.php:232
My sizecheck.phtml:
<?php
$products = $this->igetText();
?>
<div id="product_list">
<?php echo($products);?>
</div>
The block:
<?php
class Vish_SizeCheck_Block_Size extends Mage_Core_Block_Template {
public function igetText()
{
return "I am inside `" . get_class(). "` block and it is my first custom block ever !";
}
}
config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Vish_SizeCheck>
<version>0.0.1</version>
</Vish_SizeCheck>
</modules>
<frontend>
<routers>
<sizecheck>
<use>standard</use>
<args>
<module>Vish_SizeCheck</module>
<frontName>sizechecker</frontName>
</args>
</sizecheck>
</routers>
<layout>
<updates>
<vish_sizecheck>
<file>sizecheck.xml</file>
</vish_sizecheck>
</updates>
</layout>
</frontend>
<global>
<blocks>
<vish_sizecheck>
<class>Vish_SizeCheck_Block</class>
</vish_sizecheck>
</blocks>
<models>
<vish_sizecheck>
<class>Vish_SizeCheck_Model</class>
</vish_sizecheck>
</models>
<helpers>
<sizecheck>
<class>Vish_SizeCheck_Helper</class>
</sizecheck>
</helpers>
</global>
</config>
my sizecheck.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<sizecheck_index_index>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="core/template" name="sizecheck.form" as="sizecheck_form" template="Vish/sizecheck/form.phtml"/>
</reference>
</sizecheck_index_index>
</layout>
My block declaration in CMS Page:
{{block type="vish_sizecheck/size" name="sizecheck" template="Librex/sizecheck/sizecheck.phtml"}}
I can see the class is correctly inherited by:
echo get_class($this);