【问题标题】:Displaying Magento Custom Email Contact Form On One Column Layout在一列布局上显示 Magento 自定义电子邮件联系表
【发布时间】:2013-06-20 08:00:44
【问题描述】:

我一直在 Inchoo Magento – Custom email contact form with notification system 上关注本教程

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

<?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有关。

【问题讨论】:

    标签: forms magento customization contact


    【解决方案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>
    

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

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

    或通过代码实现:

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

    祝你好运!

    【讨论】:

    • 谢谢。做到了。手柄只是somefreerouternamehereno1_index_index :) 现在我几乎可以在任何地方使用!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 2021-07-29
    • 2017-12-19
    相关资源
    最近更新 更多