injecting settings into model

59 views
Skip to first unread message

nolandubeau

unread,
Feb 9, 2012, 1:29:42 PM2/9/12
to col...@googlegroups.com
Hey folks,

I might just be lacking more coffee, but I can't for the life of me get this to work.  i'm injecting a property into a persistent model like so:

property name="s3_domain" inject="coldbox:setting:profile_photo_url" persistent="false" getter="true" setter="false";
property name="s3_user_storage" inject="coldbox:setting:s3_user_storage" persistent="false" getter="true" setter="false"; 

and when I call the below function the values for s3_user_storage and s3_domain are blank.  I have verified that I have these settings in my config.  Am I missing something??

public string function getDisplayPhoto(){

if(len(trim(this.getPhoto_URL()))){

return "http://#this.gets3_user_storage()#.#this.gets3_domain()#/#this.getPhoto_URL()#";

}else{

return "";

}

}

Thanks.

Nolan

Aaron Greenlee

unread,
Feb 9, 2012, 2:55:20 PM2/9/12
to col...@googlegroups.com

Try accessing the variable directly using "variables.{property_name}" without using the THIS scope or using the implicit getter.


public string function getDisplayPhoto(){

if(len(trim(this.getPhoto_URL()))){

return "http://#variables.gets3_user_storage#.#variables.gets3_domain#/#this.getPhoto_URL()#";

}else{

return "";

}

}

nolandubeau

unread,
Feb 9, 2012, 3:17:25 PM2/9/12
to col...@googlegroups.com
Okay,

so here is my modified User.cfc Model.  I didn't have the inject on the component script and also tried referencing via variables scope.  since I have default="' on the properties it returns an empty string, however i was expecting the injected setting to be there.

Any ideas?

Thanks.

component persistent=true table="User" extends="platform.common.model.BasePersistentObjectcachename="MyCache" cacheuse="transactional" inject{

property name="userid" fieldtype="id" type="numeric" generator="native";
property name="hash" type="string";
property name="firstname" type="string";
property name="lastname" type="string";
property name="email" type="string";
property name="photo_url" type="string";

/** Inject the path for user profile photo storage */

property name="s3" inject="coldbox:myplugin:AmazonS3" persistent="false";
property name="s3_profile_photo_url" inject="coldbox:setting:profile_photo_url" persistent="false" default="";
property name="s3_user_storage" inject="coldbox:setting:s3_user_storage" persistent="false" default="";


public any function getDisplayPhoto(){

if(len(trim(this.getPhoto_URL()))){

return "http://#variables.s3_user_storage#.#variables.s3_profile_photo_url#/#this.getPhoto_URL()#";

}else{

return "";

}

}


}

Leonty Belskiy

unread,
Feb 9, 2012, 4:24:48 PM2/9/12
to col...@googlegroups.com
Do you call it from init method?
If so, dependencies in models are only available after initialization.

> --
> You received this message because you are subscribed to the Google Groups
> "ColdBox Platform" group.
> To post to this group, send email to col...@googlegroups.com
> To unsubscribe from this group, send email to
> coldbox-u...@googlegroups.com
> For more options, visit this group at
> http://groups-beta.google.com/group/coldbox
> For News, visit http://blog.coldbox.org
> For Documentation, visit http://wiki.coldbox.org

Reply all
Reply to author
Forward
0 new messages