[CB 4.0] Inject Controller into Model

73 views
Skip to first unread message

XERRANO

unread,
Mar 25, 2015, 12:24:42 AM3/25/15
to col...@googlegroups.com
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: <cfproperty name="controller" inject="coldbox" />

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



Thanks in advanced

Felipe Serrano

br...@bradwood.com

unread,
Mar 25, 2015, 1:10:26 AM3/25/15
to col...@googlegroups.com
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: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/1bc942a5-1b7e-4934-9258-0c2fa3e04f86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

XERRANO

unread,
Mar 25, 2015, 1:28:49 AM3/25/15
to col...@googlegroups.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

br...@bradwood.com

unread,
Mar 25, 2015, 1:35:16 AM3/25/15
to col...@googlegroups.com
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: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
Subject: Re: [coldbox:23904] [CB 4.0] Inject Controller into Model
From: "XERRANO" <red...@xerrano.com>
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.

XERRANO

unread,
Mar 25, 2015, 1:42:59 AM3/25/15
to col...@googlegroups.com
Thank you Brad :)
Reply all
Reply to author
Forward
0 new messages