嘿大家我收到此錯誤CakePHP致命錯誤:調用一個非對象的成員函數check()?
"Fatal error: Call to a member function check() on a non-object in C:\xampp\htdocs\job_portal_cakephp\app\Controller\Component\SeekerSessionComponent.php on line 4"
組件代碼(SeekerSessionComponent.php)
<?php
class SeekerSessionComponent extends Component{
function session_check(){
if(!$this->Session->check("id")){
die;
$this->redirect(array("controller"=>"Pages","action"=>"login"));
}
}
}
?>
控制器代碼(PagesController.php)
App::uses('AppController', 'Controller');
class PagesController extends AppController {
public $name = 'Pages';
public $helpers = array('Html', 'Session');
public $uses = array("Job","Page","Seeker","Skill");
public $components = array("Sanitize","SeekerSession");
public function index(){
$this->SeekerSession->session_check();
$this->layout = "first_layout";
$jobs = $this->Job->query();
$this->set(compact("jobs"));
}
}
我有網頁的控制器,它具有索引函數使用SeekerSessionComponent檢查是否存在變量「id」的會話。
檢查你的類,該函數是否定義? –
'App :: uses(Component,Controller);'在組件類代碼中錯過了: - https://book.cakephp.org/2.0/en/controllers/components.html#creating-a-component和function must被「公開」 –