Magento undefined variable this in custom block templateRewrite core classes or override?Magento new custom block moduleRecently product view not workingMagento custom adminhtml template gets overwritten by default templateMagento module Invalid block typeMagento 2 - Update Cart Block with Custom Discount ValueHow to create a custom block from billing.phtmlMagento - Determine what pages is available to handleModule works when in app/code but not when in vendor folderMagento 2.3.0 Get Country Name

Distinguish the explanations of Galadriel's test in LotR

How do native German speakers usually express skepticism (using even) about a premise?

Can Jimmy hang on his rope?

Why do you use the "park" gear to park a car and not only the handbrake?

Are there any sports for which the world's best player is female?

The joke office

What is the correct parsing of お高くとまる?

What happens to unproductive professors?

Does a wizard need their hands free in order to cause their familiar from the Find Familiar spell to reappear?

Found and corrected a mistake on someone's else paper -- praxis?

Efficiently defining a SparseArray function

How do you move up one folder in Finder?

Why weren't bootable game disks ever a thing on the IBM PC?

Yet another hash table in C

Why do we need common sense in AI?

How often does the spell Sleet Storm require concentration checks?

What are the indigenous English words for a prostitute?

What is this little owl-like bird?

The rigidity of the countable product of free groups

Is this a reference to the film Alien in the novel 2010 Odyssey Two?

How to tell someone I'd like to become friends without letting them think I'm romantically interested in them?

What is the parallel of Day of the Dead with Stranger things?

How to drill holes in 3/8" steel plates?

Did the Ottoman empire suppress the printing press?



Magento undefined variable this in custom block template


Rewrite core classes or override?Magento new custom block moduleRecently product view not workingMagento custom adminhtml template gets overwritten by default templateMagento module Invalid block typeMagento 2 - Update Cart Block with Custom Discount ValueHow to create a custom block from billing.phtmlMagento - Determine what pages is available to handleModule works when in app/code but not when in vendor folderMagento 2.3.0 Get Country Name






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















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);









share|improve this question
























  • Show your sizecheck.xml.

    – Sohel Rana
    Jul 1 at 15:48











  • @SohelRana that is for the route part only but will add now

    – Vaishal Patel
    Jul 1 at 15:55











  • Is it is comes in igetText()? did you try die('here') in your funciton ?

    – Ravi Soni
    Jul 1 at 17:30


















0















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);









share|improve this question
























  • Show your sizecheck.xml.

    – Sohel Rana
    Jul 1 at 15:48











  • @SohelRana that is for the route part only but will add now

    – Vaishal Patel
    Jul 1 at 15:55











  • Is it is comes in igetText()? did you try die('here') in your funciton ?

    – Ravi Soni
    Jul 1 at 17:30














0












0








0








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);









share|improve this question
















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);






magento-1.9 module






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 1 at 16:20







Vaishal Patel

















asked Jul 1 at 15:31









Vaishal PatelVaishal Patel

4206 silver badges19 bronze badges




4206 silver badges19 bronze badges












  • Show your sizecheck.xml.

    – Sohel Rana
    Jul 1 at 15:48











  • @SohelRana that is for the route part only but will add now

    – Vaishal Patel
    Jul 1 at 15:55











  • Is it is comes in igetText()? did you try die('here') in your funciton ?

    – Ravi Soni
    Jul 1 at 17:30


















  • Show your sizecheck.xml.

    – Sohel Rana
    Jul 1 at 15:48











  • @SohelRana that is for the route part only but will add now

    – Vaishal Patel
    Jul 1 at 15:55











  • Is it is comes in igetText()? did you try die('here') in your funciton ?

    – Ravi Soni
    Jul 1 at 17:30

















Show your sizecheck.xml.

– Sohel Rana
Jul 1 at 15:48





Show your sizecheck.xml.

– Sohel Rana
Jul 1 at 15:48













@SohelRana that is for the route part only but will add now

– Vaishal Patel
Jul 1 at 15:55





@SohelRana that is for the route part only but will add now

– Vaishal Patel
Jul 1 at 15:55













Is it is comes in igetText()? did you try die('here') in your funciton ?

– Ravi Soni
Jul 1 at 17:30






Is it is comes in igetText()? did you try die('here') in your funciton ?

– Ravi Soni
Jul 1 at 17:30











1 Answer
1






active

oldest

votes


















0














The solution was rather staring me in the face. Looking at the error,




'Notice: Undefined variable: this­ in...




It was not instantiating the variable $this, even though the line was set as:



 <?php
$products = $this­->igetText();
?>


Debugging this line further it revealed there was a hidden character:



The hidden character



So, deleting this line and retyping the line got everything working.






share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f280339%2fmagento-undefined-variable-this-in-custom-block-template%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The solution was rather staring me in the face. Looking at the error,




    'Notice: Undefined variable: this­ in...




    It was not instantiating the variable $this, even though the line was set as:



     <?php
    $products = $this­->igetText();
    ?>


    Debugging this line further it revealed there was a hidden character:



    The hidden character



    So, deleting this line and retyping the line got everything working.






    share|improve this answer



























      0














      The solution was rather staring me in the face. Looking at the error,




      'Notice: Undefined variable: this­ in...




      It was not instantiating the variable $this, even though the line was set as:



       <?php
      $products = $this­->igetText();
      ?>


      Debugging this line further it revealed there was a hidden character:



      The hidden character



      So, deleting this line and retyping the line got everything working.






      share|improve this answer

























        0












        0








        0







        The solution was rather staring me in the face. Looking at the error,




        'Notice: Undefined variable: this­ in...




        It was not instantiating the variable $this, even though the line was set as:



         <?php
        $products = $this­->igetText();
        ?>


        Debugging this line further it revealed there was a hidden character:



        The hidden character



        So, deleting this line and retyping the line got everything working.






        share|improve this answer













        The solution was rather staring me in the face. Looking at the error,




        'Notice: Undefined variable: this­ in...




        It was not instantiating the variable $this, even though the line was set as:



         <?php
        $products = $this­->igetText();
        ?>


        Debugging this line further it revealed there was a hidden character:



        The hidden character



        So, deleting this line and retyping the line got everything working.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 3 at 16:21









        Vaishal PatelVaishal Patel

        4206 silver badges19 bronze badges




        4206 silver badges19 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f280339%2fmagento-undefined-variable-this-in-custom-block-template%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form