• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
extending CI_form_validation don't work

#1
[eluser]Unknown[/eluser]
So i extended my form_validation library.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Lt_form_validation extends CI_Form_validation {
    
    public function __construct() {
        parent::__construct();
    }

    public function clear_field_data() {

        $this->_field_data = array();
        return $this;
    }
    
}

but when i try to reach it, i get error:
Code:
Fatal error: Call to undefined method CI_Form_validation::clear_field_data()

I trying to call like that
Code:
$this->form_validation->clear_field_data();

What i am doing wrong?

#2
[eluser]TheFuzzy0ne[/eluser]
If you want to extend the form validation class, you need to call your file MY_Form_validation.php, and the class name should be MY_Form_validation.

You can do it your way too, but you'll need to do it like this:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

include BASEPATH.'libraries/Form_validation'.EXT;

class Lt_form_validation extends CI_Form_validation {
    ...

Then you'd need to load your library like this:
Code:
$this->load->library('lt_form_validation');

And then call the methods like this:
Code:
$this->lt_form_validation->clear_field_data();

#3
[eluser]CroNiX[/eluser]
/application/libraries/MY_Form_validation.php

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation {
    
    public function __construct() {
        parent::__construct();
    }

    public function clear_field_data() {

        $this->_field_data = array();
        return $this;
    }
    
}

Code:
$this->load->library('form_validation');  //loads form validation and extends it with MY_form_validation automatically.
$this->form_validation->clear_field_data(); //call your new method

See the Extending Native Libraries section for more info.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.