遇到 PHP 错误
严重性:分析错误
消息:语法错误,意外的"$this"(T_VARIABLE(
文件名:控制器/用户.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();
}
}
构造
函数区域中缺少;
。
public function __construct() {
parent::__construct();
$this->load->model('user_model');
}
如果您使用codeigniter 3,则必须将类和文件名的第一个字母作为大写示例Welcome.php并且模型和libarary也是如此
class Welcome extends CI_Controller
。
控制器从索引public function index();
中删除了;
用户.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');
}
}
我建议通读大部分用户指南Codeigniter 3
Codeigniter Doc的页面在这里 http://www.codeigniter.com/docs