我正在为新表单开发一个自定义模块(没什么特别的)。我已经创建了一个自定义模板,我正在尝试通过我的控制器进行渲染(我也尝试过使用XML但是没有用):
$this->loadLayout();
$this->getLayout()->getBlock('blockName');
$this->renderLayout();
但是当我进入页面时,我会得到网站的页眉和页脚等,但不是内容。
以下是我的文件:
IndexController.php
<?php
class Class_Module_IndexController extends Mage_Core_Controller_Front_Action {
public function preDispatch() {
parent::preDispatch();
$this->getLayout()->getUpdate()->addHandle('module_default');
}
public function indexAction() {
$this->loadLayout();
$this->getLayout()->getBlock('blockName');
$this->renderLayout();
}
public function postAction() {
$_post = $this->getRequest()->getPost();
// form fields
$_name = $_post['name'];
$_to = $_post['email'];
$_phoneModel = $_post['phone_model'];
$_phoneNumber = $_post['phone_number'];
$_issue = $_post['issue'];
// email set up
$_subject = 'A Subject';
$_message = 'Hey, ' . $_name . 'said that there phone (' . $_phoneModel . ') has the following issue:';
$_message .= $_issue;
$_message .= 'Their number is ' . $_phoneNumber;
// magento mail set up
$_mail = Mage::getModel('core/email');
$_mail->setToName($_name);
$_mail->setToEmail($_to);
$_mail->setBody($_message);
$_mail->setSubject($_subject);
// send mail
try {
$_mail->send();
Mage::getSingleton('customer/session')->addSuccess('Email sent successfully!');
$this->_redirect('');
} catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send message. Please try again later.');
$this->_redirect('');
}
}
}
我的config.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<modules>
<Class_Module>
<version>0.1.0</version>
</Class_Module>
</modules>
<frontend>
<routers>
<module>
<use>standard</use>
<args>
<module>Class_Module</module>
<frontName>module</frontName>
</args>
</module>
</routers>
</frontend>
<!-- my attempt with xml -->
<global>
<page>
<layouts>
<module module="page" translate="label">
<label>Label</label>
<template>contacts/template.phtml</template>
<layout_handle>block_form_default</layout_handle>
</module>
</layouts>
</page>
</global>
</config>
和我的template.phtml文件:
<div id="messages_product_view">
<?= $this->getMessagesBlock()->getGroupedHtml() ?>
</div>
<div class="page-title">
<h1>Title</h1>
</div>
<form id="formId" method="POST" action="<?= $this->getFormAction() ?>">
<div class="fieldset">
<ul class="fields">
<li class="field">
<label for="name" class="required">Name</label>
<div class="input-box">
<input type="name" name="name" placeholder="John/Jane Doe" />
</div>
</li>
<li class="field">
<label for="email" class="required">Email Address</label>
<div class="input-box">
<input type="email" name="email" placeholder="example@example.co.uk" />
</div>
</li>
<li class="field">
<label for="phone_model" class="required">Phone Model</label>
<div class="input-box">
<input type="name" name="phone_model" placeholder="HTC Desire 310" />
</div>
</li>
<li class="field">
<label for="phone_number" class="required">Phone Number</label>
<div class="input-box">
<input type="number" name="phone_number" placeholder="0123456789" />
</div>
</li>
<li class="field">
<label for="issue" class="required">Issue</label>
<textarea name="issue"></textarea>
</li>
</ul>
</div>
<div class="buttons-set">
<input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
<button type="submit" title="Submit" class="button">
<span>
<span>Submit</span>
</span>
</button>
</div>
</form>
<script>
//<![CDATA
var form = new VarienForm('formId', true);
//]]>
</script>
我已经好几个小时了。任何帮助表示赞赏。
由于
答案 0 :(得分:0)
定义布局的奇怪方法(在config.xml中)。我从来没有见过这样的东西:D也许尝试使用单独的xml文件以标准方式定义布局,这里http://www.webspeaks.in/2010/07/create-your-first-magento-module.html你有教程。从5年开始,我就制作了类似的模块,并且有效:)