首頁 > 後端開發 > php教程 > codeigniter 表单验证加载失败

codeigniter 表单验证加载失败

WBOY
發布: 2016-06-06 20:40:13
原創
890 人瀏覽過

错误提示:

codeigniter 表单验证加载失败

<code>php</code><code><?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Article extends CI_Controller {
    public function __construct() {
        parent::__construct();
       
        $this->load->model('article_model', 'post');
    }
   
    public function index(){

        $this->load->view('admin/post_list.html');
    }
   
    public function add(){
        $this->load->model('category_model', 'cate');
        $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');
        }
    }
}
?>
</code>
登入後複製
登入後複製

codeigniter 表单验证加载失败

为什么

<code>php</code><code>$this->load->library('form_validation', 'verify'); 
$this->load->model('category_model', 'cate');
</code>
登入後複製
登入後複製

这两个会加载失败?

回复内容:

错误提示:

codeigniter 表单验证加载失败

<code>php</code><code><?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Article extends CI_Controller {
    public function __construct() {
        parent::__construct();
       
        $this->load->model('article_model', 'post');
    }
   
    public function index(){

        $this->load->view('admin/post_list.html');
    }
   
    public function add(){
        $this->load->model('category_model', 'cate');
        $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');
        }
    }
}
?>
</code>
登入後複製
登入後複製

codeigniter 表单验证加载失败

为什么

<code>php</code><code>$this->load->library('form_validation', 'verify'); 
$this->load->model('category_model', 'cate');
</code>
登入後複製
登入後複製

这两个会加载失败?

<code>/**
 * Class Loader
 *
 * This function lets users load and instantiate classes.
 * It is designed to be called from a user's app controllers.
 *
 * @access  public
 * @param   string  the name of the class
 * @param   mixed   the optional parameters
 * @param   string  an optional object name
 * @return  void
 */
</code>
登入後複製

第二个参数是__construct的参数,第三个才是可选的对象名称。

载入类库的时候,是不可以重命名的吧。。。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板