alt attribute in img tag in CHtml::link

Hi I am trying to add alternate text for img text in case there is no image. if I add alt text as in code snippet below i get link created for my alt text. how i can make sure that even if there is no image the link created goes to the right page instead of giving me "Invalid argument supplied for foreach() " error.


echo CHtml::link('<img alt = "image alternate text" src ="' . Yii::app()->request->baseUrl . $Album->AlbumArtUrl . '" /> <br/>', array(

                                                                                                                          'store/details/',

                                                                                                                          'album' => $Album->AlbumId

                                                                                                                        ) );

See CHtml::image()

There’s no foreach clause in the code above, so there should be an error somewhere else.

Maybe in your Album::getAlbumArtUrl(), or the codes surrounding the code above.

Try the following:




echo CHtml::link( $Album->AlbumArtUrl,('store/details/','album' => $Album->AlbumId));



If the same error occurs, the error is in Album::getAlbumArtUrl().