yiitextareayii-chtml

How to set a value in CHtml::textArea in yii


In my web application, I want to set a default value to CHtml::textArea. In my view,

<?php echo CHtml::textArea('answer' . $no, '', array('rows' => 6, 'cols' => 50, 'class' => "form-control",'value'=>$exam->answer)); ?>

But, this is not working. How can I do this?


Solution

  • You can set it directly as the second parameter:

    CHtml::textArea('answer' . $no, $exam->answer, array(
        'rows' => 6, 'cols' => 50, 'class' => "form-control")
    );
    

    See CHtml::textArea for more details.