How To Update A String As Htmlencoded String Using Update Statement In Yii

I have a update query, where I need to update the HTML encoded string in the database.

Below is the update statement -


     $model->update(array('CreatedDate','SmsText'));   

Suppose if ‘SmsText’ contains


 "A 'quote' is <b>bold</b>" 

I want it to be saved as


A 'quote' is &lt;b&gt;bold&lt;/b&gt;

I tried with the below query, but this did not work


 $model->update(array('CreatedDate',encode('SmsText')));

How can I do this

It makes more sense to store the string unencoded in the database in case you need to use it in non-HTML contexts in future. You’d then encode it in the view when outputting it to the browser:




<?= CHtml::encode($model->field); ?>