zend框架:我想显示图像。但我只能在DB的最底线显示图像
问题描述:
这是我在*中的第一个主题。我不是英语母语的人。zend框架:我想显示图像。但我只能在DB的最底线显示图像
但是我有一个问题,请回答我!
现在我正在拍一个简单的拍卖网站。
所以,现在我正在制作产品展示页面。
我想显示图像,标题,auction_endtime。
图像的名称(字符串),标题,auction_endtime从数据库中提取。
图像的数据从文件夹(/ auction/img /)中获取。
在自动我可以显示标题auction_endtime,但图像是问题。
只有显示的图像是DB的图像中最底线。
并且该图像显示在每一行中。
我无法以正确的每行显示每个图像。
我试过array_merge标题,auction_endtime和图像的数据。
但我不能使用图像的数据作为propper数组。
我在View phtml的文件中尝试使用foreach图片的数据。我不能使用图像数据作为数组。
请帮帮我。
非常感谢!
//This is Controller.
//This is zend_form for using images.
public function indexForm()
{
$form = new Zend_Form();
$form->setElementDecorators (
array (
'ViewHelper',
'errors',
array (
'decorator' => 'Description',
'options' => array (
'tag' => 'p',
'class' => 'description'
)
),
'Label'
),
array ('file'));
return $form;
}
public function indexAction()
{
$form = $this->indexForm();
//image's name(string),title,auction_endtime is fetched from DB.
$select = $this->db->select()->from('displayDB');
$result = $this->db->fetchAll($select);
//This is for fetching image's data by image's name.
foreach ($result as $key => $value) {
$form->addElement (
'image',
'submitImage',
array(
'width' => 200,
'height' => 200,
'value' => '/auction/img/'.$result[$key][file_upload],
'class' => 'fade'
)
);
//This is for view.
$this->view->assign ('image' , $form);
$this->view->assign('result',$result);
}
}
}
//This is View's phtml file.
<div class="content">
<table class="list" border="0">
<?php $image=$this->image; ?>
//Show in table.
<?php foreach($this->result as $row): ?>
<td><?php echo $image; ?></td>
<td><?php echo $row['title']; ?></td>
<td><?php echo $row['uTimedata_end']; ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
答
表单元素和视图变量都需要唯一键。在
$form->addElement (
'image',
'submitImage',
array(
'width' => 200,
'height' => 200,
'value' => '/auction/img/'.$result[$key][file_upload],
'class' => 'fade'
)
);
您每次执行这个表达式时覆盖的元素。 Als on
$this->view->assign ('image' , $form);
$this->view->assign('result',$result);
对于视图变量也是如此。
请尝试使用代码示例{}按钮来格式化您的代码。无论如何。为什么你把你的图片放入表单中? – Marcin 2011-02-08 12:11:06