遇到PHP错误
严重性:解析错误
消息:语法错误,意外'$ this'(T_VARIABLE)
文件名:controllers / user.php
行号:6
回溯:
public function __construct()
{
parent::__construct()
$this->load->model('user_model', $data);
}
从评论
更新<?php if(!defined('BASEPATH')) die("No direct Script Access allowed");
class user extends CI_Controller {
public function index(); {
if(($this->session->userdata('user_name')!="")) {
$this->welcome();
}
}
答案 0 :(得分:1)
您在构造函数区域中缺少;
。
public function __construct() {
parent::__construct();
$this->load->model('user_model');
}
如果您使用codeigniter 3,您必须将第一个字母的类和文件名作为大写示例 Welcome.php ,并且
class Welcome extends CI_Controller
与模型相同和图书馆。
Controller从索引;
public function index();
<强> user.php的强>
<?php if(!defined('BASEPATH')) die("No direct Script Access allowed");
class User extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('user_model');
}
public function index() {
if ($this->session->userdata('user_name') == TRUE) {
$this->welcome();
} else {
// Just a idea make them go to error page or something
// Up to you.
$this->some_other_function();
}
}
public function welcome() {
// Example.
$variable = $this->user_model->function();
$this->load->view('some_view', $variable);
}
public function some_other_function() {
$this->load->view('another_view');
}
}
我建议阅读大部分User Guide Codeigniter 3
和Codeigniter Doc的网页http://www.codeigniter.com/docs