织梦的蚂蚁 发表于 2012-3-31 16:39:44

Message: Undefined property: User::$form_validation,求高手帮解,谢谢

<?php
/*
* 用户中心控制器
*/
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller
{

      function __construct()
      {
            parent::__construct();
            $this->load->model('user_model');
      }

      public function index(){}
      /**
       * 用户登录函数
       * @param
       */
      public function login()
      {
            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');

            if ($this->form_validation->run() == FALSE)
            {
                  $this->load->view('login');
            }
            else
            {
                  $this->load->view('formsuccess');
            }
      }

}
?>


这段代码报错啦:

A PHP Error was encounteredSeverity: NoticeMessage: Undefined property: User::$form_validationFilename: controllers/user.phpLine Number: 40

请问该怎么解决?
谢谢!



huboo82 发表于 2012-3-31 17:37:56

本帖最后由 huboo82 于 2012-3-31 17:39 编辑

Filename: controllers/user.php
Line Number: 40
代码发出来看看。还有错误提示未定义的属性 User 类中的 form_validation
Undefined property: User :: $form_validation

织梦的蚂蚁 发表于 2012-3-31 17:46:37

huboo82 发表于 2012-3-31 17:37 static/image/common/back.gif
Filename: controllers/user.php
Line Number: 40
代码发出来看看。还有错误提示未定义的属性 User 类中的...

这个类的全部代码

<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller
{

      function __construct()
      {
            parent::__construct();
            $this->load->model('user_model');
      }

      public function index()
      {
            $data['title'] = '用户登录';
            $data['sess'] = $this->session->all_userdata();
            if (! $this->user_model->isLogined($data['sess']))
            {
                  $this->load->view('login', $data);
            }
            else
            {
                  $this->load->view('index', $data);
            }
      }

      public function login()
      {
            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');

            if ($this->form_validation->run() == FALSE)
            {
                  $this->load->view('login');
            }
            else
            {
                  $this->load->view('formsuccess');
            }

      }

}
?>



大道达人 发表于 2012-3-31 19:42:50

很不解的错误

ghnjk 发表于 2013-2-27 17:57:48

我也遇到了这样的一个错误:
后来改成下面就可以了,不知道对你是否游泳。      
      $this->load->helper(array('form', 'url'));
      $this->load->library('form_validation');
      $this->form_validation=new CI_Form_validation();
      $data['title']='Create a news item';

      $this->form_validation->set_rules('title', 'Title', 'required');
      $this->form_validation->set_rules('text', 'text', 'required');

mark35 发表于 2013-2-28 13:38:31

自动加载form_validation看看还出错不
页: [1]
查看完整版本: Message: Undefined property: User::$form_validation,求高手帮解,谢谢