I am a newbie at PHP; today I see some code as the following in Magento top.phtml.
<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<ul id="nav">
<!--NEW HOME LINK -->
<li class="home"><a href="<?php echo $this->getUrl('') ?>"><?php echo $this->__('Home') ?></a>"</li>
<!--NEW HOME LINK -->
<?php echo $_menu ?>
</ul>
</div>
<?php endif ?>
I know $this is the self of the class, it’s only used in the class to refer to the method or property, on the above code, there is no class has been defined, why it can use $this keyword directly? What does $this->__('Home') stand for?
Since you tagged this magento you likely have a class like
Mage_Catalog_Block_Navigation. At least, the methods hint at that. Now, I have no clue about Magento, but this class extends fromMage_Core_Block_Templateand in that class you have thefetchViewMethod, which at some point doesWhen you
includecode inside a method, you do have access to$thisin the included file code, because it is evaluated in the scope of that instance:General Example:
Note that “
$thisis not theselfof the class” is only partially correct.selfis also a keyword and php, but whileselfreally refers to the class,$thisrefers to the instance of a class.