2012-08-03 59 views
0

我使用验证码组件从http://www.devarticles.in/验证码组件读会话错误

我已经进口的验证码组件像

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; 
} 

回答

0

您将需要在顶部声明$控制器:public $Controller;

而变化启动()来

function startup($controller) {

$this->Controller = $controller;

}

通常我正在分配所述initialize()方法的$控制器。我不确定它是否会在startup()方法中工作,但我认为它会。

请参阅CakePHP组件部分了解更多信息。