2012-08-03 33 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組件部分了解更多信息。