Welcome Guest, Not a member yet? Register   Sign In
The problem when extend the form_validation system library
#1

[eluser]luffy[/eluser]
I create one form_validation file in my application/library directory:

filename: Form_validation.php
Class name: MY_Form_validation

The class code like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation {

....

}


The error exist when run:
Fatal error: Class 'CI_Form_validation' not found in E:\www\application\libraries\Form_validation.php on line 3
#2

[eluser]khagendra[/eluser]
filename: Form_validation.php
Class name: MY_Form_validation

the filename should be the name of class. do like this, it will work

filename: MY_Form_validation.php
Class name: MY_Form_validation
#3

[eluser]imn.codeartist[/eluser]
Ok here what you have done wrong

Make file name in your application/library directory:
MY_Form_validation.php

then in your class


Code:
class MY_Form_validation extends CI_Form_validation

{
    function mytest()
    {
        echo 'this is test';
    }
}

in your controller

Code:
class Test extends Controller
{
    function Test()
    {
        parent::Controller();
        
    }
    
    function index()
    {
        echo 'hello';

        $this->load->library('my_form_validation');
        $this->my_form_validation->mytest();
    
    }

}

I bet this will work
#4

[eluser]wiredesignz[/eluser]
Do NOT load the MY_Form_validation extension library. Load Form_validation as you would normally.
The MY_Form_validation extension class will be loaded by CodeIgniter automatically.
Code:
$this->load->library('form_validation');
$this->form_validation->mytest();

@dixcoder, I suggest you go back and read the user guide again before giving people help.
#5

[eluser]Sarwar CSE[/eluser]
Same Problem

path application/library/GSValidation.php

class :
Code:
class GSValidation extends CI_Form_validation{
function __construct() {
        parent::__construct ();
    }
    function GetMessage(){
        echo "Test SuccessFull";
    }
}

when i load the library by this $this->load->library('GSValidation') then the error shows
Code:
Fatal error: Class 'CI_Form_validation' not found in \application\libraries\GSValidation.php on line 2

Please Advice me
#6

[eluser]moriokasan[/eluser]
Just in case someone still needs this:

The error is generated by a bad naming in the file names and class names. This is in direct correlation with the prefix definition in 'config.php' file :
Code:
$config['subclass_prefix'] = 'MY_';

Considering that the prefix is 'MY_' then in application/libraries create a file named 'MY_Form_Validation.php' with content:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* Created on Mar 24, 2012
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/

class MY_Form_validation extends CI_Form_validation
{
     function __construct($config = array())
     {
          parent::__construct($config);
     }

    function yourAdditionalFunction($someParam)
    {
        
    }
    
}
?>


Then in your controller use 'form_validation' as you would normally use:

Code:
$this->load->library('form_validation');
    
    $this->form_validation->set_rules('firstname', "username", "trim|required");
    $this->form_validation->set_rules('lastname', "password", "trim|required");
    
    //run your function
    $ret = $this->form_validation->yourAdditionalFunction('The Param');

Good luck!




Theme © iAndrew 2016 - Forum software by © MyBB