Clinkcolumn - Calling Javascript Function And Passing Php Values

I’m new to YII framework, I wanted to create a link column having a image. Clicking image should call a Javascript function, PHP values need to be passed to that javascript function. here is the code,

But the HTML is not getting rendered properly. It is getting printed wrongly as,

Instead i wanted this to be printed as ,

Any help is highly appreciated!!!

Hi Raji

check by

add ‘type’=>‘raw’

an example of that

http://www.yiiframework.com/doc/api/1.1/CDetailView

but which function of Yii did you use?

The linkHtmlOptions attribute isn’t interpreted as code, so the $data variable isn’t available. You’ll probably need to build the link yourself using CHtml::link().

You’ll need to remove your ‘class’ attribute and set the ‘type’ attribute to ‘raw’, as KonApaz said.

Thanks for the suggestion KonApaz & Keith. Actually Im using a CGridView in that i have to call a javascript function, Im not sure how to use cLink in the CGridview, here is the grid view code. Can you please let me know how to add cLink to the cGridView?

It’s hard to say from the code you’ve provided, but I think you need something like this:




array(

    'header'=>'Trades',

    'type'=>'raw',

    'htmlOptions'=>array('style'=>'text-align:justify'),

    'value'=>function($data){

        return CHtml::link(

            CHtml::image(Yii::app()->baseUrl . '/images/view_all.png'),

            '#',

            array(

                'id'=>$data['id'],

                'onclick'=>"viewTrades({$data['id']})",

            )

        );

    },

),



Thanks Keith, that is the same thing which I was looking for. here is the updated code,

And it worked like charm. Thank you all for your help!

hi all here i could not find the different id when i trying to use the ‘id’=>$data[‘id’], it just shows the id as string like this “$data[‘id’]”

but need unique id for every link in the column

pls suggest me

array(

	'class' => 'CLinkColumn',


'header' => 'End date',


        'label' => 'Edit End date',


         'urlExpression'=>'Yii::app()->createUrl("/admin/index", array("id" => $data["id"]))', 


        'linkHtmlOptions'=>array('class'=>'enddate',

“id”=>’$data[“id”]’

        ),


			


			),