Mar*_*ius 12
为此,您需要一个自定义渲染器 file
表单中输入.为此创建以下类:
<?php
class {{Namespace}}_{{Module}}_Block_Adminhtml_{{Entity}}_Helper_File extends Varien_Data_Form_Element_Abstract{
public function __construct($data){
parent::__construct($data);
$this->setType('file');
}
public function getElementHtml(){
$html = '';
$this->addClass('input-file');
$html.= parent::getElementHtml();
if ($this->getValue()) {
$url = $this->_getUrl();
if( !preg_match("/^http\:\/\/|https\:\/\//", $url) ) {
$url = Mage::getBaseUrl('media').'{{entity}}'.'/'.'file' . $url; //replace this with the path to the file if you upload it somewhere else
}
$html .= '<br /><a href="'.$url.'">'.$this->_getUrl().'</a> ';
}
$html.= $this->_getDeleteCheckbox();
return $html;
}
protected function _getDeleteCheckbox(){
$html = '';
if ($this->getValue()) {
$label = Mage::helper('{{module}}')->__('Delete File');
$html .= '<span class="delete-image">';
$html .= '<input type="checkbox" name="'.parent::getName().'[delete]" value="1" class="checkbox" id="'.$this->getHtmlId().'_delete"'.($this->getDisabled() ? ' disabled="disabled"': '').'/>';
$html .= '<label for="'.$this->getHtmlId().'_delete"'.($this->getDisabled() ? ' class="disabled"' : '').'> '.$label.'</label>';
$html .= $this->_getHiddenInput();
$html .= '</span>';
}
return $html;
}
protected function _getHiddenInput(){
return '<input type="hidden" name="'.parent::getName().'[value]" value="'.$this->getValue().'" />';
}
protected function _getUrl(){
return $this->getValue();
}
public function getName(){
return $this->getData('name');
}
}
Run Code Online (Sandbox Code Playgroud)
然后,您需要告诉您将其用于文件输入.因此,在编辑表单选项卡中,在定义fiedlset后立即添加:
$fieldset->addType('file', Mage::getConfig()->getBlockClassName('{{module}}/adminhtml_{{entity}}_helper_file'));
Run Code Online (Sandbox Code Playgroud)
替换{{Namespace}}
{{Module}}并{{Entity}}
使用适当的值保留大小写.
Namespace
是模块的命名空间(D'呃),Module
是模块的名称(D'uh),实体就是你管理的.可以Article
,News
,Files
...
[编辑]
您可以通过建立自己的模块,这个模块的创造者.它解决了这些问题.
注意:我希望这不被认为是自我推销.扩展是免费的,我没有任何经济利益.
归档时间: |
|
查看次数: |
4583 次 |
最近记录: |