Abhishek Abhishek - 1 year ago 157
PHP Question

CakePHP: get current model name in a controller

I'm creating a behaviour that needs to log the current model name. How can I get the current model name from within a controller in CakePHP?

Answer Source

Your architecture is flawed when you want to get a controllers primary model name from a behavior. That's a violation of the MVC pattern. Your app should have fat models and skinny controllers.

Your Behavior already has the model instance as it is required to be passed to behaviors. You can get the name from the model object:

// Cake 2.x
// Cake 3.x

or it's alias

// Cake 2.x
// Cake 3.x
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download