Getresource is undefined in coldbox

Hi,

I’m using i18n in coldbox.

currently I’m having users module in my application. I’m getting text from resource bundles and I have no issue when below code is in layers.

We are integrating service and DAO layers for this application I moved this code to root/model/home/homeService.cfc and I’m getting Getresource is undefined error.

Please provide any solution for this and Do I need to change any settings in modules if I moved these code into modules.

<cfreturn getResource(‘userattn’,getsetting(‘lang’))’>

Regards,
Raju

That is because getResource() and other convenience methods are part of the framework super type and are only defined in “framework” files such as handlers, views, layouts, interceptors, and plugins. Your models are separate from the framework, but they can still access anything you want. You just need to inject the plugin and call the getResource() method on it like so.

component {
property name=“rb” inject=“coldbox:plugin:ResourceBundle”;

public string function usertext() {
return rb.getResource( ‘userattn’ );
}

}

Note, when you upgrade to ColdBox 4, the i18n functionality is all part of a module and instead of injecting a plugin, you’ll inject a model named “resourceBundle@i18n”.

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.

Do I need to inject anything for getsetting(‘lang’) also.
I’m having lang variable in coldbox.cfc and please suggest me best practice that where I need to add my custom variables in config.cfc.

Here’s the rule of thumb when you’re wonder what method’s you can call from a model CFC:

  1. Did you define the method right there in that CFC?
  2. Did you define the method in a superclass?
  3. Did you include a UDF library with that method?
    If the answer is no to all three of those questions, then you cannot call that method :slight_smile:

You can however inject ColdBox settings using out injection DSL:

property name=‘mySetting’ inject=‘coldbox:setting:mySetting’;

Read more on what you can inject via WireBox here:
http://wiki.coldbox.org/wiki/WireBox.cfm#Injection_DSL

Now, if I may offer some commentary/questions on your approach…

  • Are you sure you want to store the language in a setting. Settings are application-scoped and shared by all users. Usually the current locale is on a per-user basis and the getResource() function takes care of all that.
  • I noticed you are passing the “lang” setting in as the second parameter, which is not the language, but the default value. Is that what you wanted to do?
    Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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