Rendering custom view in case filter fails

In my controller I have custom method-based filter and would like to render custom "err" view in case filtering logic fails.

If I just return false from filter function (as DOC suggests) browser just shows blank page.

So I added this code to filterBlah($filterChain):


{

  if (...something fails...)          

    {

    $this->render('err'); // Render my err.php view

    return false;

    }

$filterChain->run();

}



Is that legitimate approach (rendering view directly from filter function) ?

Gleb

I am not sure, if it is possible to render view directly from filter, but better approach is to throw exception in your filter, for example:


throw new CHttpException(400,'Invalid data.');



Eventually you can use other status codes.

Finally, in your errorAction of Site controller, you can use multiple error views, depending on status code, or use one view, and multiple error messages, depending on error code(you can provide message as parameter, when you raise error).