Yii Framework Forum: Image display with Cthml::image() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Image display with Cthml::image() Rate Topic: ***** 1 Votes

#1 User is offline   SuperSonic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 22-May 11

Posted 24 May 2011 - 02:03 AM

Hi!
I'm trying to display an image in a CSS <div> tag using Chtml::image() but the browser just display a box.
here is the code :
<div class="view">
    <table>
        <tr>
            <td>
                <b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
                <?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('libele')); ?>:</b>
                <?php echo CHtml::encode($data->libele); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('annee')); ?>:</b>
                <?php echo CHtml::encode($data->annee); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('quantite')); ?>:</b>
                <?php echo CHtml::encode($data->quantite); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('modele')); ?>:</b>
                <?php echo CHtml::encode($data->modele); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('reference')); ?>:</b>
                <?php echo CHtml::encode($data->reference); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('puissance')); ?>:</b>
                <?php echo CHtml::encode($data->puissance); ?>
                <br />
     	
                <b><?php echo CHtml::encode($data->getAttributeLabel('produit')); ?>:</b>
                <?php echo CHtml::encode($data->produit); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('type_enveloppe')); ?>:</b>
                <?php echo CHtml::encode($data->type_enveloppe); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('jauge')); ?>:</b>
                <?php echo CHtml::encode($data->jauge); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('peh_methalique')); ?>:</b>
                <?php echo CHtml::encode($data->peh_methalique); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('fabriquant')); ?>:</b>
                <?php echo CHtml::encode($data->fabriquant); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('type_equipement')); ?>:</b>
                <?php echo CHtml::encode($data->type_equipement); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('numero_serie')); ?>:</b>
                <?php echo CHtml::encode($data->numero_serie); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('marque')); ?>:</b>
                <?php echo CHtml::encode($data->marque); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('capacite')); ?>:</b>
                <?php echo CHtml::encode($data->capacite); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('num')); ?>:</b>
                <?php echo CHtml::encode($data->num); ?>
                <br />

                <b><?php echo CHtml::encode($data->getAttributeLabel('tbl_station_id')); ?>:</b>
                <?php echo CHtml::encode($data->tbl_station_id); ?>
                <br />
            </td>
            
            <td>
                <?php echo CHtml::image(dirname(Yii::app()->getBasePath()).DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'gallery'.DIRECTORY_SEPARATOR.'java.jpg', 'DORE'); ?>
            </td>
        </tr>
    </table>
</div>


See the preview in error.jpg attached.
Thanks for your help.
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,339
  • Joined: 12-October 09
  • Location:Croatia

Posted 24 May 2011 - 02:05 AM

Check the HTML source... see the image path there... and check if it's OK...
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   SuperSonic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 22-May 11

Posted 24 May 2011 - 03:03 AM

The generated html is :
<td> 
    <img src="C:\server\www\myserver.dev\public_html\gimto.client\images\gallery\java.jpg" alt="DORE" />            </td> 


This path is good, I pasted it in the browser and it display the image.
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,339
  • Joined: 12-October 09
  • Location:Croatia

Posted 24 May 2011 - 03:14 AM

It's not good because it is a full path... your browser cannot read from c:\server\... I hope you understand that...

instead of getBasePath() use Yii::app()->request->baseUrl
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   SuperSonic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 22-May 11

Posted 24 May 2011 - 03:58 AM

I solved it using :
<td>
    <?php echo CHtml::image('images/gallery/java.jpg', 'DORE'); ?>
</td>


Thanks for your help!
0

#6 User is offline   queen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 25-January 12

Posted 22 February 2012 - 06:35 AM

hi..

i am getting the image... but i have to display the image name when i point the image..
that is,.i have to display the alt name...

is it possible using chtml::image...or i have use someother method to display it..

thanks..
0

#7 User is offline   jet2230 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 09-October 12

Posted 24 October 2012 - 05:57 PM

View PostMaurizio Domba, on 24 May 2011 - 03:14 AM, said:

It's not good because it is a full path... your browser cannot read from c:\server\... I hope you understand that...

instead of getBasePath() use Yii::app()->request->baseUrl


been searching for this on the net for ages, thank you
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users