2014-03-03 67 views
0

我的问题是,当我想告诉我的形象,我没有得到任何更多细节:我有两个实体OneToOne关系,这是我的看法:视图助手2

<?php 
       $form = $this->form; 
       $form->setAttribute('action', $this->url(
         'blog', 
         array(
           'action' => 'edit', 
           'id'  => $this->id, 
         ) 
       )); 
       $form->setAttribute('class', 'contact_form'); 
       $form->setAttribute('method', 'post'); 
       $form->setAttribute('enctype','multipart/form-data'); 
       $form->prepare(); 
      ?> 
      <?php 
       echo $this->form()->openTag($form); 
       $image = $form->get('image'); 
      ?> 
        // here i have the problem 
      <img src="../../../upload/<?php $image->get('url')?>" alt="> 

我试了一下<?php $image->get('url')?>但我没有得到我的网址!

+0

好@Sam如果你有任何解决方案,它会很好,我是Zend Framework的初学者,至少我这次想要一些帮助。 – Mohammadov

+1

如果你想显示一个元素的值,你需要访问一个元素的值。这是你应该需要的所有帮助。 – Sam

回答

0

我认为你需要echo $ image-> get()返回的值。

+0

thnx @oxtub,但我们不能这样做,因为我会得到这个错误:Zend \ Form \ Element类的对象无法转换为字符串 – Mohammadov

2

由于错误消息指出您无法回显对象。表单对象确实有一些方法的,你可以在你的情况Zf2 Element Documentation.

找到我假设你希望得到您的图像标记的“src”属性,所以你必须:

echo $image->getAttribute('src');