用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1997|回复: 1
收起左侧

[HELP] 【求助】表单验证加载失败

[复制链接]
发表于 2014-12-16 11:39:11 | 显示全部楼层 |阅读模式
本帖最后由 筱戈 于 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复制代码
 
<?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'); 这个也会加载失败?
发表于 2014-12-16 13:53:30 | 显示全部楼层
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 {} )

本版积分规则