我想添加一个可以被插件中的所有函数访问的变量,但我得到一个变量未定义的错误。这里是我的插件:如何范围一个变量,使其可用于同一CFC中的其他功能(CFWheels插件)?
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;
}
}
我所说的插件从我Sessions.cfc控制器:
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);
}
}
当我倾倒
this.secretKey
插件里面,我得到一个变量未定义的错误。该错误告诉我,this.secretKey
不可用于Sessions.cfc控制器。但是我不是从Sessions.cfc转储,我从插件的CFC中倾销,如您所见。为什么?我怎样才能在我的插件范围
this.secretKey
,以便它可以通过setCookie()访问?到目前为止,variables
和this
都失败了,无论我是在函数,伪构造函数还是init()中添加定义。为了好的措施,我扔了variables.wheels.class.rememberME
,无济于事。
这里的错误:
Component [controllers.Sessions] has no acessible Member with name [secretKey]
请发布您使用的CFML a)调用init()和b)调用remember()。 –