I’ve gotta be looking right through something. I’m extending CController, and want to dynamically determine what the model class is for the current controller / action. Is there somewhere that the name is stored? Or a standard way to extract it from the web request?
My intention is to find / add an easy way to get a new model object wherever I need it, including in parent classes.
[edit] For example, if the code in an application component (created upon application startup) wants to know what model(s) are in use so it can perform a statistical function on each model, how can it find that out?[/edit]
Thank you for the reply, I appreciate the help. I got a hint about what I might need to do from your last point about [font="Courier New"]CController::action. [/font]
My goal is/was to create a function that determines which model(s) the controller is currently using. The more I look into it, the more it makes sense that I’ll need to roll my own (simple) functionality for each controller - model relationship, and won’t be able to create a [font=“Courier New”]ControllerEx[/font] class with a method that just handles this like [font=“Courier New”]YiiBase::app()->getController()[/font] handles controllers.
Unless someone has a better idea, I’ll create an abstract function in [font=“Courier New”]ControllerEx[/font] and each of my controllers will be required to implement [font=“Courier New”]getActiveModels()[/font].
I’m a newbie, so am used to what yiic generates, but understand that that’s just one way to relate controllers to models. I had been looking at the generated CRUD controllers, and realized that SiteController doesn’t follow that pattern since its model, LoginForm, doesn’t match the yiic generation pattern, therefore I couldn’t universally use the action / controller prefix to determine the model.
I ran into a similar issue and ended up extending CController. It’s part of my extension library (psYiiExtensions) called CPSController. It’s in SVN but not yet packaged.