我目前有这个设置在magento自定义网格中显示我的目录图像 - 我似乎很接近但似乎无法调用最终图像网址显示 - 任何人都可以帮助我吗?
我也试过从/ media / remote / cache调用它们但是无济于事: - (
public function render(Varien_Object $ row){
$p = Mage::getModel('catalog/product')->load($row->getproduct_id());
$html = '<img src="' . Mage::getBaseUrl('media').'catalog/product/'.'" width="50" height="50" alt="' . $p->getname() . '" />';
return $html;
}
答案 0 :(得分:0)
你必须像下面那样创建自定义渲染
只需将其添加到您的网格
即可 $this->addColumn('thumbnail',
array(
'header'=> Mage::helper('catalog')->__('Thumbnail'),
'type' => 'image',
'width' => '100',
'index' => 'thumbnail',
'renderer' => 'NAMESPACE_YOURMODULE_Block_Widget_Grid_Column_Renderer_Image',
));
并在
创建渲染类\NAMESPACE\YOURMODULE\Block\Widget\Grid\Column\Renderer\Image.php
并将以下代码添加到具有正确类名
的此文件中class NAMESPACE_YOURMODULE_Block_Widget_Grid_Column_Renderer_Image
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
protected static $showImagesUrl = null;
protected static $showByDefault = null;
protected static $imagesWidth = null;
protected static $imagesHeight = null;
protected static $imagesScale = null;
public function render(Varien_Object $row)
{
return $this->_getValue($row);
}
protected static function initSettings()
{
if(!self::$showImagesUrl)
self::$showImagesUrl = (int)Mage::getStoreConfig('yourmodule/images/showurl') === 1;
if(!self::$showByDefault)
self::$showByDefault = (int)Mage::getStoreConfig('yourmodule/images/showbydefault') === 1;
if(!self::$imagesWidth)
self::$imagesWidth = Mage::getStoreConfig('yourmodule/images/width');
if(!self::$imagesHeight)
self::$imagesHeight = Mage::getStoreConfig('yourmodule/images/height');
if(!self::$imagesScale)
self::$imagesScale = Mage::getStoreConfig('yourmodule/images/scale');
}
protected function _getValue(Varien_Object $row)
{
self::initSettings();
$noSelection = false;
$dored = false;
if ($getter = $this->getColumn()->getGetter())
{
$val = $row->$getter();
}
$val = $val2 = $row->getData($this->getColumn()->getIndex());
$noSelection = ($val == 'no_selection' || $val == '') ? true : $noSelection;
$url = Mage::helper('yourmodule')->getImageUrl($val);
if(!Mage::helper('yourmodule')->getFileExists($val))
{
$dored = true;
$val .= "[*]";
}
$dored = (strpos($val, "placeholder/")) ? true : $dored;
$filename = (!self::$showImagesUrl) ? '' : substr($val2, strrpos($val2, "/")+1, strlen($val2)-strrpos($val2, "/")-1);
$val = ($dored) ?
("<span style=\"color:red\" id=\"img\">$filename</span>") :
"<span>". $filename ."</span>";
$out = (!$noSelection) ?
($val. '<center><a href="#" onclick="window.open(\''. $url .'\', \''. $val2 .'\')" title="'. $val2 .'" '. ' url="'.$url.'" id="imageurl">') :
'';
$outImagesWidth = self::$imagesWidth ? "width='".self::$imagesWidth."'":'';
if(self::$imagesScale)
$outImagesHeight = (self::$imagesHeight) ? "height='".self::$imagesHeight."'":'';
else
$outImagesHeight = (self::$imagesHeight && !self::$imagesWidth) ? "height='".self::$imagesHeight."'":'';
//return '<img src="'.(Mage::helper("catalog/image")->init($productItem, "small_image")->resize(self::$imagesWidth)).'" '.$outImagesWidth.' '.$outImagesHeight.' alt="" />';
$out .= (!$noSelection) ?
"<img src=".(Mage::helper("catalog/image")->init($row, $this->getColumn()->getIndex())->resize(self::$imagesWidth))." ".$outImagesWidth." ".$outImagesHeight." border=\"0\"/>" :
// "<img src=".$url." ".$outImagesWidth." ".$outImagesHeight." border=\"0\"/>" :
// "" :
"<center><strong>[".__('NO IMAGE')."]</strong></center>";
return $out. ((!$noSelection)? '</a></center>' : '');
}
希望这对您有所帮助。