0

How can I convert the text TbButton bootstrap into CHtml::link in Yii? below is the TbButton bootstrap code:

$this->widget('bootstrap.widgets.TbButton', array(
    'label'=>'Data Protection Policy - Must Read for Consultant',
    'type'=>'primary', // '', 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'
    'htmlOptions'=>array('class'=>'addContactBtn','onclick'=>'js:(function(){
        $("#pdpaModal").modal({"show":true});
        return false;    
})();')));

I need to convert the code above into CHtml:

CHtml::link("Change Status", "#", array("onClick"=>"(function(){
   $("#pdpaModal").modal({"show":true});
   return false;    
})();"))

However, I get an error on the onClick part. Can anyone help me to fix it? Thanks.

Siguza
  • 21,155
  • 6
  • 52
  • 89
CnV
  • 381
  • 4
  • 20

1 Answers1

1

You need to escape double quote within double quote.

Either:

CHtml::link("Change Status", "#", array("onClick"=>"(function(){
   $(\"#pdpaModal\").modal({\"show\":true});
   return false;    
})();"));

or

CHtml::link("Change Status", "#", array("onClick"=>'(function(){
   $("#pdpaModal").modal({"show":true});
   return false;    
})();'));

Read: http://php.net/manual/en/language.types.string.php

Godzilla
  • 308
  • 2
  • 12