【求助】表单验证加载失败
本帖最后由 筱戈 于 2014-12-16 11:40 编辑错误提示:
A PHP Error was encounteredSeverity: Notice
Message:Undefined property: Article:: $verify
Filename: admin/article.php
Line Number: 26
Fatal error:Call to a member function run() on a non-object in E:\htdocs\icms\app\controllers\admin\article.php on line 26
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Article extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('category_model', 'cate');
$this->load->model('article_model', 'post');
}
public function index(){
$this->load->view('admin/post_list.html');
}
public function add(){
$data['category'] = $this->cate->fetch();
$this->load->helper('form');
$this->load->view('admin/post_add.html', $data);
}
public function save(){
$this->load->library('form_validation', 'verify');
$status = $this->verify->run('article');
if ($status) {
$data = array(
'title' => $this->input->post('title'),
'cid' => $this->input->post('category'),
'date' => $this->input->post('date'),
'keyword' => $this->input->post('keyword'),
'description' => $this->input->post('description'),
'excerpt' => $this->input->post('excerpt'),
'thumbnail' => $this->input->post('thumbnail'),
'password' => $this->input->post('password'),
'content' => $this->input->post('content')
);
$this->post->add($data);
success('admin/article', '添加文章成功');
} else {
$this->load->helper('form');
$this->load->view('admin/post_add.html');
}
}
}
为什么 $this->load->library('form_validation', 'verify'); 这个会加载失败?还有如果将 $this->load->model('category_model', 'cate'); 放在 add() 函数里也会出现下面的提示:
A PHP Error was encounteredSeverity: Notice
Message:Undefined property: Article:: $cate
Filename: admin/article.php
Line Number: 19
Fatal error:Call to a member function fetch() on a non-object in E:\htdocs\icms\app\controllers\admin\article.php on line 19
为什么$this->load->model('category_model', 'cate'); 这个也会加载失败?
1. 確認你的 config\form_validation.php 內有 article 驗證規則
2. 應避免使用關鍵字來做簡寫 $this->post->add($data);
3. 若在 add() 放入 $this->load->model('category_model', 'cate');
則必須放在 $data['category'] = $this->cate->fetch(); 之前
4. $this->load->model('category_model', 'cate'); 加載失敗
請檢查路徑與 model 名稱正確
(包括檔名與 class Category_model extends CI_Model {} )
页:
[1]