1

我是 Magento CE 的新手,我正在努力学习设计一个新主题。我已经开始研究默认的设计包。有一件事我无法理解:

这是 page.xml 中的标题部分:

<block type="page/html_header" name="header" as="header">
                <block type="page/template_links" name="top.links" as="topLinks"/>
                <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
                <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
                    <label>Navigation Bar</label>
                    <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/>
                </block>
                <block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
                    <label>Page Header</label>
                    <action method="setElementClass"><value>top-container</value></action>
                </block>
            </block>

这是header.phtml:

<div class="header-container">
    <div class="header">
        <?php if ($this->getIsHomePage()):?>
        <h1 class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a></h1>
        <?php else:?>
        <a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a>
        <?php endif?>
        <div class="quick-access">
            <?php echo $this->getChildHtml('topSearch') ?>
            <p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
            <?php echo $this->getChildHtml('topLinks') ?>
            <?php echo $this->getChildHtml('store_language') ?>
        </div>
        <?php echo $this->getChildHtml('topContainer'); ?>
    </div>
</div>
<?php echo $this->getChildHtml('topMenu') ?>

我无法理解为什么要加载 topSearch 块,即使它没有在 page.xml 的标头中声明为标头的子项。

谁能解释一下?谢谢!

4

1 回答 1

4

在主题的 layout/catalogsearch.xml 中,您将看到这个:

<reference name="header">
     <block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>

The Catalogsearch is an own module in Magento's core. When digging deeper into magento and developing own modules/overriding core modules, you will notice that this is the normal way to add "dependent" things to the layout. When you disable the catalogsearch module, topSearch will not be added to the header anymore automatically.

Imagine if you would disable it, and the XML would still call for the block - the more modules you have, the more a mess it would be, as you would have to check all existing layout files every time you disable a module if it is somewhere in there.

==UPDATE==
Regarding your comment:
Magento as a whole mainly consists of modules in the three namespaces found in app/code/, namely core, community and local. While community and local are for extensions (in magento-language just another word for modules) installed via Magento Connect or built by yourself, the core-namespace contains the magento codebase. All of the modules make up a normal magento installation, but they are still "modules". They can be disabled individually, changed, overridden and so on.

If you want a list of modules installed in your store, I recommend this extension: https://github.com/firegento/firegento-debug/

If you want to know more about the magento structure, you should read Alan Storm's series at magentocommerce.com: http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-1-introduction-to-magento, as well as everything else written by him ;)

There is also a list of all classes and functions used in magento-core: http://docs.magentocommerce.com/

于 2013-03-30T16:07:13.127 回答