从 1.7.3 升级到 2.0.0 出现的session错误
本帖最后由 veicn 于 2012-12-6 19:57 编辑程序从CodeIgniter1.7.3 升级到2.0.0 后出现这样的错误
A PHP Error was encounteredSeverity: Notice
Message: Undefined property: Panel:: $data
Filename: core/Model.php
Line Number: 50
A PHP Error was encounteredSeverity: Notice
Message: Indirect modification of overloaded property bl_userlib:: $data has no effect
Filename: models/bl_userlib.php
Line Number: 5
在bl_userlib.php 文件中 第5行是这样的
class Bl_userlib extends CI_Model {
function __construct() {
parent::__construct();
$this->data ['cookie'] = get_cookie ( md5 ( 'User__cms' ) );
$this->data ['session'] = $this->session->userdata ( md5 ( 'User__cms' ) );
}
在Panel.php 是这样的
class Panel extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper ( 'cookie' );
$this->load->library ( 'session' );
$this->load->library ( array ('helper', 'form_validation' ) );
$this->form_validation->set_error_delimiters ( '<p class="error">', '</p>' );
$this->load->model ( 'bl_userlib' );
}
这是怎么回事?请教~
$this->data 从哪里赋值的啊? 本帖最后由 veicn 于 2012-12-6 19:07 编辑
Hex 发表于 2012-12-6 18:33 static/image/common/back.gif
$this->data 从哪里赋值的啊?在这里赋的值,调试的时候发现get_cookie ( md5 ( 'User__cms' ) ); 和 $this->session->userdata ( md5 ( 'User__cms' ) ) 取到的值都是 flase,赋值的时候都赋上了 set_cookie ( md5 ( 'User__cms' ), md5 ( $params ) );和 $this->session->set_userdata ( md5 ( 'User__cms' ), md5 ( $params ) );取得时候都是空的。
<?php if (! defined ( 'BASEPATH' )) exit ( 'No direct script access allowed' );
class Bl_userlib extends CI_Model {
function __construct() {
parent::__construct();
$this->data ['cookie'] = get_cookie ( md5 ( 'User__cms' ) );
$this->data ['session'] = $this->session->userdata ( md5 ( 'User__cms' ) );
}
function result($param = false) {
if ($param === false) {
if (! empty ( $this->data ['cookie'] ) && ! empty ( $this->data ['session'] )) {
if ($this->data ['cookie'] == $this->data ['session']) {
echo '<script language="javascript">top.location="' . site_url ( 'panel/index' ) . '";</script>';
}
}
} else {
if (empty ( $this->data ['cookie'] ) && empty ( $this->data ['session'] )) {
echo '<script language="javascript">top.location="' . site_url ( 'panel/login' ) . '";</script>';
}
}
}
function seting($param = false, $params = '') {
if ($param === false) {
set_cookie ( md5 ( 'User__cms' ), md5 ( $params ) );
$this->session->set_userdata ( md5 ( 'User__cms' ), md5 ( $params ) );
} else {
delete_cookie ( md5 ( 'User__cms' ) );
$this->session->unset_userdata ( md5 ( 'User__cms' ) );
}
}
}
?> 报错行是哪个? Hex 发表于 2012-12-6 19:07 static/image/common/back.gif
报错行是哪个?
bl_userlib.php 中的 这两行 $this->data ['cookie'] = get_cookie ( md5 ( 'User__cms' ) );
$this->data ['session'] = $this->session->userdata ( md5 ( 'User__cms' ) );
谢谢 Hex~
A PHP Error was encounteredSeverity: Notice
Message:Undefined property: Panel::$data
Filename: core/Model.php
Line Number: 50
A PHP Error was encounteredSeverity: Notice
Message:Indirect modification of overloaded property Bl_userlib::$data has no effect
Filename: models/bl_userlib.php
Line Number: 5
A PHP Error was encounteredSeverity: Notice
Message:Undefined property: Panel::$data
Filename: core/Model.php
Line Number: 50
A PHP Error was encounteredSeverity: Notice
Message:Indirect modification of overloaded property Bl_userlib::$data has no effect
Filename: models/bl_userlib.php
Line Number: 6
A PHP Error was encounteredSeverity: Notice
Message:Undefined property: Panel::$data
Filename: core/Model.php
Line Number: 50
本帖最后由 veicn 于 2012-12-6 19:58 编辑
Hex 发表于 2012-12-6 19:07 static/image/common/back.gif
报错行是哪个?
这两行~
$this->data ['cookie'] = get_cookie ( md5 ( 'User__cms' ) );
$this->data ['session'] = $this->session->userdata ( md5 ( 'User__cms' ) );
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Pane l:: $ data
Filename: core/Model.php
Line Number: 50
A PHP Error was encountered
Severity: Notice
Message: Indirect modification of overloaded property Bl_userlib :: $ data has no effect
Filename: models/bl_userlib.php
Line Number: 5
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Panel :: $ data
Filename: core/Model.php
Line Number: 50
A PHP Error was encountered
Severity: Notice
Message: Indirect modification of overloaded property Bl_userlib :: $ data has no effect
Filename: models/bl_userlib.php
Line Number: 6
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Panel :: $ data
Filename: core/Model.php
Line Number: 50
谢谢Hex~ 先执行 $this->data = array(); 试试 Hex 发表于 2012-12-7 09:48 static/image/common/back.gif
先执行 $this->data = array(); 试试
问题解决,谢谢帮助~ CI_Model 类中有data这个成员属性吗?根本就没有,而且你在Bl_userlib 中竟然是用了$this->data来引用这个成员属性。我实在想不出来不出错的理由。 veicn 发表于 2012-12-7 10:33 static/image/common/back.gif
问题解决,谢谢帮助~
变量先定义后使用是个好习惯。呵呵
页:
[1]