This will insert the description meta tag automatically into the layout when the render() function gets called.

Another solution would be to use a parent controller with the property $pageDescription. That way we don't have to make a function-call to set the description. Instead, we can easily modify the description inside of the controller. In the layout-file we'll simply echo the meta tag (if defined).

As you can see, the second solution is probably better to work with because we can directly access $pageDescription and won't have to call an ugly long function every time. On the other hand, we have now additional php-code in the layout. Well that's not bad at all, but it could lead to problems.

What if we have 10 different layouts? What if we use several themes? In each of these files we would've to insert that snippet. Now let's think instead of a single string (the description), we would implement the same functionality for several rss-feed meta tags (an array). That would mean we have to do a foreach inside of the layout(s).

For a more flexible solution, we extend CController with a custom function.

When the render() function gets called, ExtendedCController will first execute the custom beforeRender() function in our parent-controller to insert the meta tag and after that it will call the original CController::render() function.

That means with this solution we can access the $pageDescription property inside of the controller and we don't have to add any special code to the layout. Of course this solution comes in handy especially for things like the already noted rss-feeds.

Tip: Since the two classes ParentController and ExtendedCController are no real controllers (they only function as parent-classes), you have to put them into the components folder (eg protected/components).