如何在admin中添加IndexController

时间:2014-06-26 06:11:06

标签: magento

<?php
class Main_Contacts_AdminhelloController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {

        $this->loadLayout();

    //create a text block with the name of "example-block"
        $block = $this->getLayout()
        ->createBlock('core/text', 'example-block')
        ->setText('<h1>This is a text block</h1>');

        $this->_addContent($block);

        $this->_setActiveMenu('main')->renderLayout();      


    }
}

如果我写了这段代码就可以,但是当我使用setFormAction而不是createBlock时,它会导致错误,我想在管理部分中使用这个方法。

IndexController.php

public function indexAction()
    {
        $this->loadLayout();
        $this->getLayout()->getBlock('contactForm')
            ->setFormAction( Mage::getUrl('*/*/post') );

        $this->_initLayoutMessages('customer/session');
        $this->_initLayoutMessages('catalog/session');
        $this->renderLayout();
    }

如果有人告诉我,我该如何使用此代码。

1 个答案:

答案 0 :(得分:0)

你可以这样使用我认为这是我所知道的唯一方式 类magento_SimpleContact_IndexController扩展Mage_Adminhtml_Controller_Action

public function indexAction()
{
$this->loadLayout();
    $block = $this->getLayout()->createBlock(
        'Mage_Core_Block_Template',
        'magento.simple_contact',
        array(
            'template' => 'magento/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();**

在我的联系人文件 app / design / frontend / default / default / template / magento / simple_contact.phtml