Image display with Cthml::image()


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">




                <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 />




                <?php echo CHtml::image(dirname(Yii::app()->getBasePath()).DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'gallery'.DIRECTORY_SEPARATOR.'java.jpg', 'DORE'); ?>





See the preview in error.jpg attached.

Thanks for your help.

Check the HTML source… see the image path there… and check if it’s OK…

The generated html is :


    <img src="C:\server\www\\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.

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

I solved it using :


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


Thanks for your help!


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…


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