View photo after save to database

Hi guy,

i can upload pic to database by refer to file to database. but how i can display the pic from view site after save to database… The wiki show how to display image step. but i not really understand the following code, what the my_link_name stand for?

Displaying images: ¶

[b]In the view we put the code:

[/b]

<? echo CHtml::link(my_link_name,array(‘displaySavedImage’,‘id’=>$model->primaryKey)); ?

Help help. anyone can help me??

Thank.

It’s just the link text. You can do this:


<? echo CHtml::link("Click here to view image",array('displaySavedImage','id'=>$model->primaryKey)); ?>

Note that you have to implement the actionDisplaySavedImage method into your controller. It’s in the wiki as well.

Please take a look at the class references if you not understand a code: CHtml::link

This code displays a link with the ‘my_link_name’ as text to show the image:




  echo CHtml::link('Show the image',array('displaySavedImage','id'=>$model->primaryKey));



If you want to see the image immediatly you can add following code:


  

  $imageUrl = $this->createUrl('displaysavedimage',array('id'=>$model->primaryKey));

  echo CHtml::image($imageUrl); 



thank for the reply… i try to do it now… Thank again. =)

Hi Joblo,

If you want to see the image immediatly you can add following code:


  $imageUrl = $this->createUrl('displaysavedimage',array('id'=>$model->primaryKey));

  echo CHtml::image($imageUrl); 

i put this code inside controller or view side??

thank…

This code is in the view.

In a controller action normally no output (echo, CHtml::XX …) should be generated.