我有一个链接的图像,我需要为其指定由php字符串生成的高度和宽度html属性。我已经考虑过使用 getimagesize,但它看起来不像我需要的。我目前正在使用社交引擎。
这是我调用图像链接的字符串。
<?php echo $this->htmlLink($item->getHref(), $this->itemPhoto($item, 'null'), array('class' => '')) ?>
输出类似于 <a href="#"><img src="#" class="null"/></a>
的 HTML 内容
我需要修改 php 以创建一个指定为 110px x 110px 的图像即<a href="#"><img src="#" class="null" width="110" height="110"/></a>
谁能给我一个例子来说明我如何写我的字符串?
你必须使用这个:
<?php echo $this->htmlLink(
$item->getHref(),
$this->itemPhoto(
$item,
'null',
null,
array('width' => '110px', 'height' => '110px')),
array('class' => '')
) ?>
也就是说,向函数添加第四个参数数组itemPhoto
。
Socialengine是Zend框架的扩展。您应该尝试查看itemPhoto
、htmlLink
等函数的定义,以便自定义它们。例如itemPhoto
可以在这里找到 - ''application''modules''Core''View''Helper''ItemPhoto.php
最后一个参数用于此,不是吗?
$this->htmlLink(
$item->getHref(),
$this->itemPhoto($item, '', '', array('width' => 110, 'height' => 110)),
array('class' => '')
);
方法1:只需为空类添加样式
<?php echo $this->htmlLink($item->getHref(), $this->itemPhoto($item, 'null'), array('class' => '')) ?>
如:
.null {
height: 110px;
width: 110px;
}
方法2:或者,可以将内联样式属性传递为:
<?php echo $this->htmlLink($item->getHref(), $this->itemPhoto($item, 'null'), array('class' => '', 'style' => 'height: 110px; width: 110px')) ?>
我看不到函数 htmlLink(( 背后的内容,但我想由于您传递的那些元素的名称,您可以编写。
echo '<a href="'.$item->getHref().'"><img src="'.$this->itemPhoto($item, 'null').'" class="null" width="110" height="110"/></a>';
但是以太发布该功能或只是尝试错误!