プラグインのすべての関数からアクセスできる変数を追加したいのですが、変数未定義エラーが発生します。これが私のプラグインです:
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
、変数の未定義エラーが発生します。このエラーは、 Sessions.cfcコントローラーthis.secretKey
で使用できないことを示しています。しかし、ご覧のとおり、Sessions.cfc からダンプしているのではなく、プラグインの CFC からダンプしています。なんで?this.secretKey
setCookie() でアクセスできるようにプラグインをスコープするにはどうすればよいですか? これまでのところ、定義を関数、疑似コンストラクター、または init() に追加するかどうかにかかわらず、失敗していますvariables
。this
おまけに、私は を投入しましたvariables.wheels.class.rememberME
が、役に立ちませんでした。
エラーは次のとおりです。
Component [controllers.Sessions] has no acessible Member with name [secretKey]