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
Aaron1
February 9, 2012, 7:55pm
#2
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 “”;
}
}
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.BasePersistentObject” cachename=“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
February 9, 2012, 9:24pm
#4
Do you call it from init method?
If so, dependencies in models are only available after initialization.