我目前已经习惯了Code Igniter并试图自己创建一个小型的假影院系统,我可以轻松地将数据添加到数据库但是能够将其拉回导致此错误的问题
我的数据库名为codeigniter,表名为movies
这是控制器
<?php
class Cinema extends CI_Controller {
public function __construct() {
parent::__construct();
$this -> load -> model("Cinema_model");
}
public function index() {
$this -> load -> helper("form");
$this -> load -> library("form_validation");
// Validation Rules
$this -> form_validation -> set_rules("title", "Movie Name", "required");
$this -> form_validation -> set_rules("startTime", "Start", "required");
$this -> form_validation -> set_rules("endTime", "End", "required");
$this -> form_validation -> set_rules("cost", "Cost", "required");
if ($this -> form_validation -> run() == false) {
$this -> load -> view("cinema_add");
} else {
$this -> cinema_model -> insert_movie();
$this -> load -> view("formsuccess");
}
}
public function getFilms() {
$data['movies'] = $this -> cinema_model -> getfilms();
$this -> load -> view("cinemalistings", $data);
}
}
?>
这是我的模特
<?php
class Cinema extends CI_Controller {
public function __construct() {
parent::__construct();
$this -> load -> model("Cinema_model");
}
public function index() {
$this -> load -> helper("form");
$this -> load -> library("form_validation");
// Validation Rules
$this -> form_validation -> set_rules("title", "Movie Name", "required");
$this -> form_validation -> set_rules("startTime", "Start", "required");
$this -> form_validation -> set_rules("endTime", "End", "required");
$this -> form_validation -> set_rules("cost", "Cost", "required");
if ($this -> form_validation -> run() == false) {
$this -> load -> view("cinema_add");
} else {
$this -> cinema_model -> insert_movie();
$this -> load -> view("formsuccess");
}
}
public function getFilms() {
$data['movies'] = $this -> cinema_model -> getfilms();
$this -> load -> view("cinemalistings", $data);
}
}
?>
我的观点
<?php
print_r($movies);
?>
我确定代码很好,当被要求其他人查看时,他们说它应该没问题,但我在尝试加载getFilms页时遇到错误
遇到PHP错误
严重性:注意
消息:未定义属性:Cinema :: $ cinema_model
文件名:controllers / cinema.php
行号:30
致命错误:在第30行的/opt/lampp/htdocs/cinema/application/controllers/cinema.php中的非对象上调用成员函数getfilms()
我也尝试过查看其他人的例子,看看我是否做得对,并且更改了代码仍然是同样的错误
任何帮助
感谢
答案 0 :(得分:1)
您有错误的错误:
在MODEL中:
class Cinema extends CI_MODEL {
public function __construct() {
parent::__construct();
$this -> load -> model("Cinema_model");
}
答案 1 :(得分:1)
&#34;致命错误:调用未定义的方法CI_DB_mysql_result :: results_array()&#34;
它&#39; S
result_array();
(不是)不是
results_array()