如何在Magento的其他目录/页面中访问$ this-> getChildHtml()等方法?

All I want to do is move a search box. This search box is currently displayed in the header, directly next to the logo, and is generated by the following code:

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

in /app/design/frontend/MYTHEME/default/template/page/html/header.phtml

I would like this search box inline with the navigation links, which are located in top.phtml which is located in another directory. But when I use the code

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

the search box does not appear. I understand that this is because the meaning of $this has changed, but what I don't understand is how to display the search box? What do I replace $this with?

I tried replacing it with Mage_Page_Block_Html_Header since that was the definition of $this in header.phtml, but to no avail. Can anybody point me in the right direction, or provide an explanation as to how I access methods once the definition of $this has changed?

You need to make layout update and include block topSearch into block containing top.phtml. Look into app/design/frontend/.../layouts/...xml files, find how topSearch is declared and then find where the block using top.phtml template is declared. Then move topSearch block as a child of top block. I mean add layout xml update like this:

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

Another solution is try next in your template:

echo $this->getLayout()->getBlock('top.search')->toHtml()

If it would not work then find in layouts topSearch block and try to use in code above name of block instead of alias.

You can read more about Magento view level here: http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/0_-_theming_in_magento/designing-for-magento

Good luck!