I want to add a variable that can be accessed by all functions in a plugin, but I'm getting a variable undefined error. Here's my plugin:
component
mixin="Controller"
{
public any function init() {
this.version = "1.0";
return this;
}
public void function rememberMe(string secretKey="rm_#application.applicationName#") {
this.secretKey = arguments.secretKey;
}
public void function setCookie(required string identifier) {
// Create a cookie with the identifier and encrypt it using this.secretKey
// this.secretKey is not available, though, and an error is thrown
writeDump(this.secretKey); abort;
}
}
I call the plugin from my Sessions.cfc controller:
component
extends="Controller"
{
public void function init() {
// Call the plugin and provide a secret key
rememberMe("mySecretKey");
}
public void function remember() {
// Call the plugin function that creates a cookie / I snipped some code
setCookie(user.id);
}
}
When I dump
this.secretKey
inside the plugin, I get a variable undefined error. The error tells me thatthis.secretKey
is not available in Sessions.cfc controller. But I'm not dumping from Sessions.cfc, I'm dumping from the plugin's CFC, as you can see. Why?How can I scope
this.secretKey
in my plugin so that it can be accessed by setCookie()? So farvariables
andthis
have failed, whether I add the definitions in a function, a pseudo-constructor, or the init(). For good measure, I threw invariables.wheels.class.rememberME
, to no avail.
Here's the error:
Component [controllers.Sessions] has no acessible Member with name [secretKey]