Cakephp 验证码组件读取会话错误

Cakephp 验证码组件读取会话错误,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,我正在使用来自 我已经导入了captcha组件,如 App::import('Component', 'Captcha'); //load it $this->Captcha = new CaptchaComponent(new ComponentCollection()); //make instance $this->Captcha->startup($this); 但当我尝试调用函数作为 $captcha = $this->Capt

我正在使用来自

我已经导入了captcha组件,如

    App::import('Component', 'Captcha'); //load it
    $this->Captcha = new CaptchaComponent(new ComponentCollection()); //make instance
    $this->Captcha->startup($this);
但当我尝试调用函数作为

    $captcha = $this->Captcha->getVerCode();
它给我错误的感觉

Call to a member function read() on a non-object in C:\xampp\htdocs\westudy_old\app\Controller\Component\CaptchaComponent.php on line 65
我的组件功能是

function getVerCode() {
    return $this->Controller->Session->read('security_code');
}
    function startup() {
    $this->Controller = $this->_controller;
}
组件的启动功能是

function getVerCode() {
    return $this->Controller->Session->read('security_code');
}
    function startup() {
    $this->Controller = $this->_controller;
}

您需要在顶部声明$Controller:
public$Controller

并将startup()更改为

功能启动($controller){

$this->Controller=$Controller;

}

通常我在initialize()方法中分配$controller。我不确定它是否能在startup()方法中工作,但我认为它会工作


有关更多信息,请参见组件部分。

我猜您正在CakePHP 2.x中使用它。CakePHP 2.x验证码组件的最新工作版本可在作者的网站上获得