开发者

Magento - Layout file not working for custom module

开发者 https://www.devze.com 2023-03-26 01:13 出处:网络
I\'m creating a custom module for a page with an email form on. Everything seems to work fine but I cant get my layout updates to work. This is my first custom module so any help would be great. Thank

I'm creating a custom module for a page with an email form on. Everything seems to work fine but I cant get my layout updates to work. This is my first custom module so any help would be great. Thank you.

app/code/local/Adtrak/ArrangeSurvey/ect/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <adtrak_arrangesurvey>
            <version>0.1.0</version>
        </adtrak_arrangesurvey>
    </modules>
    <global>
        <rewrite>
            <adtrak_arrangesurvey>
                <from><![CDATA[#^/arrangesurvey/#]]></from>
                <to>/adtrakArrangeSurvey/</to>
            </adtrak_arrangesurvey>
        </rewrite>
    </global>
    <frontend>
        <routers>
            <adtrak_arrangesurvey>
                <use>standard</use>
                <args>
                    <module>Adtrak_ArrangeSurvey</module>
                    <frontName>adtrakArrangeSurvey</frontName>
                </args>
            </adtrak_arrangesurvey>
        </routers>
        <layout>
            <updates>
                <adtrak_arrangesurvey>
                    <file>adtrakArrangeSurvey.xml</file>
                </adtrak_arrangesurvey>
            </updates>
        </layout>
    </frontend>
</config>

app/design/frontend/doorfit/deafult/layout/adtrakArrangeSurvey.xml

<?xml version="1.0"?>
<layout version="0.1.0">

<adtrak_arrangesurvey_index_index>
    <label>Arrange A Survey</label>
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
            <action method="setHeaderTitle" translate="title" module="arrangesurvey"><title>Arrange A Survey</title></action>
        </reference>
        <reference name="content">
            <block type="core/template" name="surveyForm" template="arrangesurvey/index.phtml"/>
        </reference>
    </adtrak_arrangesurvey_index_index>

    <adtrak_arrangesurvey_thanks_index>
        <label>Thank You</label>
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>开发者_JS百科;
            <action method="setHeaderTitle" translate="title" module="contacts"><title>Thank You</title></action>
        </reference>
        <reference name="content">
            <block type="core/template" name="surveyForm" template="arrangesurvey/thanks.phtml"/>
        </reference>
    </adtrak_arrangesurvey_thanks_index>
</layout>

app/code/local/Adtrak/ArrangeSurvey/controllers/IndexController.php

I've inserted the form block here because I couldnt get the layout file working so hopefully I can remove that after.

require_once 'Mage/Contacts/controllers/IndexController.php';

class Adtrak_ArrangeSurvey_IndexController extends Mage_Contacts_IndexController
{

   public function indexAction()
    {
        $this->loadLayout();

        $block = $this->getLayout()->createBlock(
        'Mage_Core_Block_Template',
        'arrangesurvey.form',
        array('template' => 'arrangesurvey/index.phtml')
        );


        $this->getLayout()->getBlock('content')->append($block);

        $this->renderLayout();

    }

    public function postAction()
    {
      Mage::log('postAction rewritten');
        $post = $this->getRequest()->getPost();
        if ( $post ) {
            $translate = Mage::getSingleton('core/translate');
            /* @var $translate Mage_Core_Model_Translate */
            $translate->setTranslateInline(false);
            try {
                $postObject = new Varien_Object();
                $postObject->setData($post);

                $error = false;

                if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
                    $error = true;
                }

                if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {
                    $error = true;
                }

                if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                    $error = true;
                }
                if ($error) {
                    throw new Exception();
                }
                $mailTemplate = Mage::getModel('core/email_template');
                /* @var $mailTemplate Mage_Core_Model_Email_Template */
                $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                    ->setReplyTo($post['email'])
                    ->sendTransactional(
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                        null,
                        array('data' => $postObject)
                    );

                if (!$mailTemplate->getSentSuccess()) {
                    throw new Exception();
                }

                $translate->setTranslateInline(true);

                $this->_redirect('arrangesurvey/thanks');

                return;
            } catch (Exception $e) {
                $translate->setTranslateInline(true);

                Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
                $this->_redirect('*/*/');
                return;
             }

        } else {
            $this->_redirect('*/*/');
        }
    }

}

Any help or advice would be great.


Try to replace

<adtrakArrangeSurvey_index_index>

with

<Adtrak_ArrangeSurvey_index_index>

May be there is another errors. But this is the first I met

0

精彩评论

暂无评论...
验证码 换一张
取 消