ねえ、誰もが、私はこのエラーを取得しています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 and function must 「公然」である –