【发布时间】:2017-07-20 08:50:18
【问题描述】:
大家好,我遇到了这个错误
"致命错误:在非对象上调用成员函数 check() C:\xampp\htdocs\job_portal_cakephp\app\Controller\Component\SeekerSessionComponent.php 第 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"));
}
}
我有 Pages 控制器,它具有索引功能,它使用 SeekerSessionComponent 来检查是否存在带有变量“id”的会话。
【问题讨论】:
-
检查你的类是否定义了这个函数?
-
App::uses(Component, Controller);在您的组件类代码中丢失:- book.cakephp.org/2.0/en/controllers/… 并且函数必须是public