custom application or custom controller?

I am working on a sample app where I would like to include some css and js tags in the layout based on some logic.

Because of the business restrictions I cannot do this inside the layout/main.php

Now my question is where to insert clientscript->register… code?

Should I extend CWebApplication and override the init() method.

or should I extend CController and override the init() method.


I would extend the controller. Does this help you? You can adopt that concept for clientScript easily. If you need more help let me/us know.

In your controller’s action. Just do your logic there before the render.

Thank you all for the advice. If anyone cares to know - this is the way I solved the challange:

  1. Because I needed to have a central place to decide what css goes on top and an additional requirement for being able to share sum function everywhere - I have extended the CWebApplication. This required me to change the index.php and instruct to run the web app using my extended CWebApplication class.

  2. In order to problematically add/skip the inclusion of css/js files on top using the extended CWebApplication - I have extended the CController class and used this extension onward.