无法加载布局或未检测到的phtml

时间:2016-03-21 07:31:20

标签: php magento

好吧,我现在不知道问题是什么。但似乎我无法加载布局或phtml。 这是我的代码

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');
    }
}

1 个答案:

答案 0 :(得分:0)

您是否在控制器操作中添加了此内容

 $this->loadLayout();  
 $this->renderLayout(); 

此代码应位于索引控制器内。