Welcome Guest, Not a member yet? Register   Sign In
Validation in autoload PHP 4 (Fix suggested)
#19

[eluser]lostsock[/eluser]
Just thought I should point out to PHP 4 users that you cannot load the validation library in the class constructor. You have to load it specifically in the function or via autoload.

The following will fail in PHP 4
Code:
class Test extends Controller {
    function Test() {
        parent::Controller();
        // LOADING THE validation CLASS FROM THE CONTROLLER WILL FAIL IN PHP 4
        $this->load->library('validation');
    }
    
    function index() {
        // Prep Validation
        $rules['author']    = "trim|required";
        $this->validation->set_rules($rules);

        $fields['author']    = 'Author';
        $this->validation->set_fields($fields);
        
        if (empty($_POST)) {
            $this->validation->author = "Testing";
        }
        
        // Run validation
        if ($this->validation->run() == FALSE) {
            $this->load->view('admin/category');
        } else {
            die('woohoo!');
        }
    }
}
To make it work you must either add it to the autoload array or call $this->load->library('validation'); from within the method itself
Code:
function index() {
    $this->load->library('validation');
    // ETC...
}

Hope this saves someone else a couple of hours work Wink


Messages In This Thread
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 01-16-2008, 08:05 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 01-17-2008, 09:59 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 01-17-2008, 10:01 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 03:10 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 03:38 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 04:19 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 04:25 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 01:51 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 02:20 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 02:26 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 02:55 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 01:37 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:41 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:43 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:44 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:59 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 03:36 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-22-2008, 04:06 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 08-30-2008, 05:42 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 09-02-2008, 08:50 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 09-02-2008, 08:54 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 09-02-2008, 09:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB