Question

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,

<pre>
array(
'class'=>'CLinkColumn',
 'header'=> 'Trades',
 'imageUrl' => '/images/view_all.png',
 'htmlOptions'=>array('style'=>'text-align:justify'),
 'linkHtmlOptions'=>array("id"=>'$data["id"]','onclick'=>'viewTrades($data["id"])')
),
</pre>

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

<pre>
<a href="javascript:void(0)" onclick="viewTrades($data['id'])" id='$data['id']'><img alt="Link" src="/images/view_all.png"></a>
</pre>

Instead i wanted this to be printed as ,

<a href="javascript:void(0)" onclick="viewTrades(317)" id="317"><img alt="Link" src="/images/view_all.png"></a>

Any help is highly appreciated!!!

Était-ce utile?

La solution

I figured it out by myself, here is the code. Hope it might be useful for someone!

    'name'=>'trades', 
                    'value'=>'CHtml::link("View",array("view", "id"=>$data["id"]), array("id"=>$data["id"],  "class"=>"linkClass", "onclick"=>"viewTrades($data[id]); "))',
            'type'=>'raw',
            ),
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top