2015-07-20 69 views
0

我有一个Magento主题的网站,我发现这个代码PHP。这是什么意思PHP代码? Magento

<div class="product-options sss" id="product-options-wrapper"> 
    <?php echo $this->getChildHtml('', true, true);?>      
    <?php if ($this->hasRequiredOptions()):?> 
     <p class="required"><?php echo $this->__('* Required Fields') ?></p> 
    <?php endif;?> 
</div> 

在这段代码中谁是this?我的div?

getChildHtml('', true, true); 

从我,我意识到,''在互联网上找到意味着所有的孩子一个div(其格?)

我不明白是什么参数用于布尔true true ...帮助他们?

我在网上找到它getChildHtml方法从XML文件中取得东西。我可以在哪里找到这个文件?

你能给我解释一个简单的示例代码吗?

提前致谢!

回答

3

$此在上面的代码是指当前类(对象)。

'getChildHtml'方法根据参数中提供的块名称或别名呈现子块。

<?php echo $this->getChildHtml('',true,true) ?> 
  • 第一个参数是名称或一个孩子块的别名。如果提供,它将返回该子块的输出。如果此参数未提供或作为空白字符串传递,则呈现布局中指定的所有子块。
  • 第二个参数$ useCache是​​一个默认为true的布尔值。如果是,则在管理面板中的缓存设置下启用块缓存时,该块将被缓存。如果为false,即使启用块缓存,块也不会被缓存。
  • 第三个参数$ sorted也是一个布尔值,默认为 false。如果是,则根据 属性之前和之后定义的排序顺序呈现子块。

实施例:

<?php echo $this->getChildHtml('content') ?> 

在上面的例子中被添加到Magento的布局XML中应用程序/设计/前端/碱/默认/布局/ page.xml

这是我们如何在XML文件中创建块:

<block type="core/text_list" name="content" as="content" translate="label"> 
    <label>Main Content Area</label> 
</block>