new method in controller: beforeRender()

I think it would make sense to have a beforeRender() method in the controller that is called just before any output is send to the client (it could be called as a first thing by render()).

In my web application (ajax) I want to send status information and messages in a json header. I cannot send the header in beforeAction() because I still want to set some json data in the action itself. Neither I want to send the header in the action, since that whould mean repeating code. Currently I am sending the header in the layout view, though I always have to use a layout now. Also there is some more logic involved before sending the header which does not really belong into the layout view. I could use output buffering and send the header in afterAction(), somehow I don't like that approach

A beforeRender() method would solve the whole problem. What do you think?

You may override render() method and insert beforeRender() at the beginning of the method.

thanx qiang, i will do that.

What do you think of including it as a standard in Yii?

The reason we don't include it in the core is because render() can be called arbitrarily, and thus beforeRender() may lose its original intention.

ok, I see your point.

Would this problem be solved if we make sure that beforeRender() is only called after the first call of render() (have a flag in the controller)?

To make the solution complete beforeRender() would also have to be called from renderText() I think.

The problem is: we can also use 'echo', 'renderPartial' to display page content.