How to pass array data in a url?

Hi All,

I would like to pass my array data into a url:

this is the array data:

array(‘dealPayments/buy’, ‘dealid’ => $model->id),

Which I would like to pass into a <a> so when someone clicks and image it gets send to the url set by the array data.

I tried this:

echo CHtml::link(

but it is unfortunately echoing the <a> tag inside my href, I only need the url with the arrway data at the end , how to do this please?

Thank you,

Ben

You can use createUrl or createAbsoluteUrl


Yii::app()->createAbsoluteUrl('controller/action', array('lang' => 'en'));

You can put a link on an image like this:


echo CHtml::link(CHtml::image(Yii::app()->baseUrl . '/images/myimage.gif'), array('controller/action'));

Thank you Moginn,

Is it the same for both Yii 1 and Yii 2 please?

Thank you,

Ben

In Yii 2 to create a link you should use Html::a

http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#a()-detail

to create an image you should use Html::img

http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#img()-detail

to create url you should use Url

http://www.bsourcecode.com/yiiframework2/yii2-url-creation/

Thank you so much!

The last link you gave me is a bit of a gold mine (: thats exactly what I was looking for!

Thanks,

Ben