form_validation class does not load (codeigniter)

依然范特西╮ 提交于 2019-12-10 17:45:41

问题


My script fails to load form_validation class.

I called it from autoload.php, controller's _construct method and the method i was intend to use (ie. login() method)

autoload.php

$autoload['libraries'] = array('database', 'Login', 'Template', 'form_validation', 'session');

controller

<?php
class Login extends CI_Controller
{
function __construct()
{
    parent::__construct();
    $this->load->model('user_model');
    $this->load->library('form_validation');
}

function logmein()
{       
    $this->load->library('form_validation');
    $this->form_validation->set_rules('userEmail', 'email', 'trim|required|valid_email|callback__check_login');
    $this->form_validation->set_rules('userPassword', 'password', 'trim|required');

please do note that, i did not try to load the class from all the three places, i tried each one solely, and the combinations, but no success. I'm running PHP Version 5.3.5 on my localhost with XAMPP on windows 7. My real server is linux so if it works well on linux, i can live with that =)

update: i have var_dumped and checked the resources, and both _user_model_ and _form_validation_ seem to work well. however, when i var_dump($this->user_model) or var_dump($this->form_validation) returns NULL.


回答1:


All of my code was actually error-less.

However in one of my library classes, i have extended a controller class to load another library which was causing all of my errors.

I have removed it and used $CI =& get_instance(); method for loading other classes and everything works fine now.




回答2:


You have two Login classes which are being loaded simultaneously. I'll bet money that they are causing a collision. Change the name of the Library class to LoginTools or something like that, and that will help.



来源:https://stackoverflow.com/questions/6708287/form-validation-class-does-not-load-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!