将值设置为adminhtml表单模板中的字段

时间:2014-03-24 07:25:07

标签: php magento

我为管理表单标签创建了一个模板文件:

class Excellence_Designer_Block_Adminhtml_Designer_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs {

    protected function _beforeToHtml() {
        $this->addTab('images', array(
            'label' => Mage::helper('designer')->__('Images'),
            'title' => Mage::helper('designer')->__('Images'),
            'content' => $this->getLayout()->createBlock('designer/adminhtml_designer_edit_tab_images')->toHtml(),
        ));

        return parent::_beforeToHtml();
    }

}

class Excellence_Designer_Block_Adminhtml_Designer_Edit_Tab_Images extends
Mage_Adminhtml_Block_Template implements
Mage_Adminhtml_Block_Widget_Tab_Interface {

    public function _construct() {
        parent::_construct();
        $this->setTemplate('designer/edit/tab/images.phtml');
    }

    public function getTabLabel() {
        return $this->__('Images');
    }

    public function getTabTitle() {
        return $this->__('Images');
    }

    public function canShowTab() {
        return true;
    }

    public function isHidden() {
        return false;
    }

}

images.phtml

<div class="input-field">
    <label for="image">Custom Field</label>
    <input type="text" class="input-text" name="image" id="image" />
</div>

但如果我想编辑表单

,那里没有任何价值

screen shot甚至将值保存在数据库中。另一个标签是使用Mage_Adminhtml_Block_Widget_Form创建的,并显示了字段中的值,但为此我怎样才能获得该值?

2 个答案:

答案 0 :(得分:0)

你的EditAction()必须阻碍你。看看吧。

public function editAction() 
       {
        $newsId = $this->getRequest()->getParam('id');
        $newsModel = Mage::getModel('news/news')->load($newsId);

        if ($newsModel->getId() || $newsId == 0) {
        $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
        if (!empty($data)) {
                $model->setData($data);
            }

            Mage::register('news_data', $newsModel);

            $this->loadLayout();
            $this->_setActiveMenu('news/items');

            $this->_addBreadCrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
            $this->_addBreadCrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));

            $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);

            $this->_addContent($this->getLayout()->createBlock('news/adminhtml_news_edit'))
                 ->_addLeft($this->getLayout()->createBlock('news/adminhtml_news_edit_tabs'));

            $this->renderLayout();

        }
        else
            {
                Mage::getSingleton('adminhtml/session')->addError(Mage::helper('news')->__('Item does not exist'));
                $this->_redirect('*/*/');

            }
       }

答案 1 :(得分:0)

我会找到一个解决方案,不知道这是正确的方法,但在我的情况下有效。如果您有更好的解决方案,请告诉我。

我在 images.phtml

中进行了更改
<div class="input-field">
    <label for="image">Custom Field</label>
    <input type="text" value="<?php echo $this->getValue(); ?>" class="input-text" name="image" id="image" />
</div>

并在相应的块文件中添加了一个方法

public function getValue() {
    return Mage::registry('designer_data')->getImage();
}