[CB 4.0] Inject Controller into Model

Hi guys,

I need to have access to cbController, and I guess controller is not being injected into models…
The way I work is to inject controller into my model using:

Is this OK? or I’m doing something stupid?

Thanks in advanced

Felipe Serrano

Are you saying that injection syntax doesn’t work and you don’t know why, or does work but you’re not sure if it’s the correct approach?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks Brad, and sorry for being a mess while explaining…

The injection works great, but I was thinking by injecting “coldbox” into a model I was doing something that you don’t supposed to do. Sinse I just cannot call getController() inside a model function, I try by injecting the controller and that worked.

Thanks

No, that injection is correct. The reason the convenience method getController() doesn’t exist is because your models don’t inherit from the framework super type like handlers, views, layouts, etc do. You can add it in your own base class, or use the mixins functionality in WireBox, but we don’t do it for you since your models ideally should operate outside the framework as much as possible. It’s rare that I need to inject the controller, but what you have is the correct way to do it.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thank you Brad :slight_smile: