在一个列布局上显示Magento自定义电子邮件联系表单

时间:2013-06-20 08:00:45

标签: forms magento customization contact

我一直在Inchoo Magento – Custom email contact form with notification system

上关注本教程

我已经有了它的工作,但他有代码在三个comlumn布局上显示联系表单,我需要在一个列布局上显示它。以下是我认为相关的代码:

<?php
class Inchoo_SimpleContact_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        //Get current layout state
        $this->loadLayout();
        $block = $this->getLayout()->createBlock(
            'Mage_Core_Block_Template',
            'inchoo.simple_contact',
            array(
                'template' => 'inchoo/simple_contact.phtml'
            )
        );

        $this->getLayout()->getBlock('content')->append($block);
        //$this->getLayout()->getBlock('right')->insert($block, 'catalog.compare.sidebar', true);
        $this->_initLayoutMessages('core/session');
        $this->renderLayout();
    }

    public function sendemailAction()
    {
        //Fetch submited params
        $params = $this->getRequest()->getParams();
        $mail = new Zend_Mail();
        $mail->setBodyText($params['comment']);
        $mail->setFrom($params['email'], $params['name']);
        $mail->addTo('mail@mybelovedangels.com', 'Some Recipient');
        $mail->setSubject('Test Inchoo_SimpleContact Module for Magento');
        try {
            $mail->send();
        }
        catch(Exception $ex) {
            Mage::getSingleton('core/session')->addError('Unable to send email. Sample of a custom notification error from Inchoo_SimpleContact.');


        }
        //Redirect back to index action of (this) inchoo-simplecontact controller
        $this->_redirect('inchoo-simplecontact/');
    }
}
?> 

我一直在网上寻找答案,但我没有幸运得到任何工作。我认为这与Mage_Core_Block_Template有关。

1 个答案:

答案 0 :(得分:1)

抓住你的布局句柄(类似于inchoo_simplecontact_index_index)并做一些layout.xml魔术:

<inchoo_simplecontact_index_index>
      <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
      </reference>
</inchoo_simplecontact_index_index>

也许句柄是不同的naemd,通过以下方式在被叫控制器中抓取:

Zend_Debug::dump(Mage::app()->getLayout()->getUpdate()->getHandles());

或通过代码执行:

$template = Mage::getConfig()->getNode(‘global/page/layouts/one_column/template’);
$this->getLayout()->getBlock(‘root’)->setTemplate($template);
祝你好运!