config.xml中
<modules>
<Email_Rent><!-- code/local/Email/Rent-->
<version>1.0.0</version>
</Email_Rent>
</modules>
<global>
<!-- Declare block class -->
<blocks>
<rent><!-- route -->
<class>Email_Rent_Block</class>
</rent>
</blocks>
</global>
<frontend>
<routers>
<rent>
<use>standard</use>
<args>
<module>Email_Rent</module>
<frontName>rent</frontName>
</args>
</rent>
</routers>
<!-- declare layout for block -->
<layout>
<updates>
<rent><!-- route -->
<file>rent.xml</file>
</rent>
</updates>
</layout>
</frontend>
这是rent.xml
<layout version="0.1.0">
<rent_index_index>
<reference name="content">
<block type="rent/indexblock" name="form_rent_block" template="rent/rent_form.phtml" />
</reference>
</rent_index_index>
我已经放了var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
在我的索引控制器中。并打印出“rent_index_index”
indexcontroller.php
class Email_Rent_IndexController extends Mage_Core_Controller_Front_Action
{
public function IndexAction() {
$this->loadLayout();
$this->renderLayout();
//echo 'test index';
}
public function saveAction()
{
//getrequest->getpost is same as $_request/$_get/$_post function
// get data from afficher.phtml same as View
$name = ''.$this->getRequest()->getPost('name'); //textfield nom
$email = ''.$this->getRequest()->getPost('email'); //textfield prenom
$telephone = ''.$this->getRequest()->getPost('telephone'); //textfield telephone
//if all textfield is been filled
if(isset($name)&&($name!='') && isset($email)&&($email!='') && isset($telephone)&&($telephone!='') )
{
//save data / insert sql
$contact = Mage::getModel('test/test');
$contact->setData('name', $name);
$contact->setData('email', $email);
$contact->setData('telephone', $telephone);
$contact->save();
}
//on redirige l’utilisateur vers la méthode index du controller indexController
//de notre module <strong>test</strong>
$this->_redirect('index.php/test');
}
}
答案 0 :(得分:0)
您是否在控制器操作中添加了此内容
$this->loadLayout();
$this->renderLayout();
此代码应位于索引控制器内。