Yii自定义错误字段

hello guys I am trying to create a custom error field for all of my models where in this field will contain all of the errors what ever the current controller/action is.. like for example in my main.php:

<header>
...
</header>

<div id="container">
    <div id="my_custom_error_field">
        <?php //all models error goes in here ?>
    </div>

    <div id="dynamic_content">
        <?php echo $content; ?>
    </div>
</div>

<footer>
...
</footer>

my question is how will I do this? is there a built in method that gets the current models errors?? should I create a widget for this?

Thanks in advance..

If you are using CActiveForm, you can use $form->errorSummary($model);:

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'my-form',
    'enableClientValidation'=>false,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>

    <div id="my_custom_error_field">
        <?= $form->errorSummary($model); ?>
    </div>

    # The rest of the form goes here...

    <?php echo CHtml::submitButton('Submit', array('class'=>'btn btn-primary')); ?>

<?php $this->endWidget(); ?>

If you want all the errors for a model, use $model->getErrors();

<div id="my_custom_error_field">
    <?php 
        $errors = $model->getErrors();
        foreach($errors as $key => $error) {
            // echo out to page
        }
    ?>
</div>