[eluser]Unknown[/eluser]
I tried to extend the Validation class by putting this code in /application/libraries and called it MY_Validation.php. When I try to include the validation class the method in this class comes back with an error that it does not exist. Please be patient with me I am very new to CI and need some help!
This is the extension: in /application/libraries
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Validation extends CI_Validation {
function My_Validation()
{
parent::CI_Validation();
}
function set_default_values($data, $value=NULL)
{
if (is_array($data) == TRUE)
{
foreach($data as $field => $value)
{
$this->$field = $value;
$_POST[$field] = $value;
}
}
else
{
$this->$data = $value;
$_POST[$data] = $value;
}
}
}
?>
This is the controller:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Formtest extends Controller {
function Formtest()
{
parent::__construct();
}
function index()
{
$this->load->library('validation');
$this->load->helper('form');
$rules['text'] = 'required';
$rules['option'] = 'required';
$rules['select'] = 'required';
$rules['radio'] = 'required';
$this->validation->set_rules($rules);
$fields['text'] = 'text field';
$fields['select'] = 'select field';
$fields['check'] = 'check box field';
$fields['radio'] = 'radio field';
$this->validation->set_fields($fields);
if (count($_POST) == 0)
{ // For initial load set defualt values
$this->validation->set_default_values('text','hello world');
$this->validation->set_default_values('select', 'select2');
$this->validation->set_default_values('check', 'check2');
$this->validation->set_default_values('radio', '3');
}
if ($this->validation->run() == FALSE)
{
$this->load->view('formtest_view');
}
else
{
$this->load->view('formtest_view');
}
}
}
?>
When trying to access $this->validation->set_default_values('text','hello World') I get the following error:
Fatal error: Call to undefined method CI_Validation:
et_default_values() in /home/hector/www/test/ce/system/application/controllers/formtest.php on line 28
Note: I followed the user guide to follow this and don't understand why the method or my extension is not being loaded by CI ver. 1.6.3
Thanks in advance!