2011-02-08 5 views
0

これは私の最初のトピックですstackoverflow。英語のネイティブスピーカーではありません。zend framework:画像を表示したい。私はイメージを表示することができますDBのほとんどの一番下の行

しかし、私はbiginnerの質問が1つあります。私に答えてください!

今、私は単純なオークションのウェブサイトを作っています。

今、私は製品の表示ページを作っています。

私はshow image、title、auction_endtimeが欲しいです。

イメージの名前(文字列)、タイトル、auction_endtimeがDBから取得されます。

イメージのデータは、フォルダ(/オークション/ img /)から取得されます。

私はタイトル、auction_endtimeを表示できますが、画像に問題があります。

DBの画像では、表示される画像は一番下の行です。

その画像はすべての行に表示されます。

すべての画像をそれぞれの行で正しく表示することはできません。

私は、array_merge title、auction_endtime、およびimageのデータを試しました。

しかし、私はイメージのデータをプロッパー配列として使用できません。

そして、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> 
+0

コードサンプル{}ボタンを使用してコードの書式を設定してください。とにかく。なぜイメージをフォームに入れるのですか? – Marcin

+0

次回は、コードの書式設定に必要な時間をかけてください。これは、より大きな回答を得るのに役立ちます。ありがとう –

答えて

0

フォーム要素とビュー変数の両方に固有のキーが必要です。

$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); 

ビュー変数でも同じことが起こります。

関連する問題