How I Can Set Custom Error To Show In A Form View?


I wish to customize some error when an event is verified.

In the ClassnameController.php I have a code with some checks: I wish to specify a custom error (to show in the form) when an event is verified.

How it’s possible?


Hi tab,

What do you mean by "an event"? What do you check in the controller?

You may consider using flash message.

if (someValidation() === false) {

    Yii::app()->user->setFlas('error', 'You may not do it.');



And in the view of xxx/yyy:

<?php if(Yii::app()->user->hasFlash('error')): ?>

<div class="flash-error">

<?php echo Yii::app()->user->getFlash('error'); ?>


<?php endif; ?>