Welcome Guest, Not a member yet? Register   Sign In
[Solved] - Problem in loading Validation Library
#1

[eluser]Prasanna[/eluser]
Hi all,

I have presented my code below which causes error on my server. But i have tested the same code in some other server, it works fine.

If i load the validation library in the constructor then it’s working fine. But i needs to know why it has to be loaded in the constructor as i does not need the validation library in all the functions of the sample class.

I have also gone through the core files and found that there is function called "get_instance" with return the instance of the current controller (i.e., $this).

Instead of using like the following, which causes error

Code:
//Type 1
$this->validation->set_rules($rules);

Alternatively i have tried using like the following which works fine.

Code:
//Type 2
$this->get_instance()->validation->set_rules($rules);

To my knowledge $this && $this->get_instance() are the same.

If not, let me know the difference.

So may i know what causes error in the server. The same problem occurs while loading some models. Do i needs to check any php.ini settings ?

Code:
<?php
class Sample extends Controller
{
    //Constructor
    function Sample()
    {
        parent::Controller();
    }

    function index()
    {
        //Load the required libraries.
        $this->load->library('validation');
        
        //Set the validation rules
        $this->_loginFrmRules();
    }

    function _loginFrmRules()
    {
        
        $rules['admin_name']        = 'trim|required';
        
        //Type 1 - Causes Error
        $this->validation->set_rules($rules);
        
        //Type 2 - Working Fine
        $this->get_instance()->validation->set_rules($rules);

        $fields['admin_name']        = 'Username';

        $this->validation->set_fields($fields);
    }
}
?>
#2

[eluser]jeephnx[/eluser]
Hi. I seem to have the opposite problem.

1) If I load the validation library in the constructor, the validation fields do not display.

2) If I load the validation library in the function, the validation fields display correctly.

The validation rule runs fine in either case (it correctly returns TRUE or FALSE).

This only happens on my Linux server. On my PC server its fine.
#3

[eluser]manilodisan[/eluser]
The validation should work as you have the code, however, try:

Code:
<?php
class Sample extends Controller
{
    //Constructor
    function Sample()
    {
        parent::Controller();
    }

    function index()
    {        
        //Set the validation rules
        $this->_loginFrmRules();
    }

    function _loginFrmRules()
    {
        //Load the required libraries.
        $this->load->library('validation');

        $rules['admin_name']        = 'trim|required';
        
        //Type 1 - Causes Error
        $this->validation->set_rules($rules);
        
        //Type 2 - Working Fine
        $this->get_instance()->validation->set_rules($rules);

        $fields['admin_name']        = 'Username';

        $this->validation->set_fields($fields);
    }
}
?>
#4

[eluser]Prasanna[/eluser]
For me this solution got worked

Use the following line in the .htaccess file.

php_flag zend.ze1_compatibility_mode off

For more info have a look @ this

http://ellislab.com/forums/viewthread/52308/P15/#450647
#5

[eluser]admiral[/eluser]
Hi all,

A lot of time elapsed but I have similar problem while using set_rules() function from form_validation library. I tried to add
Code:
php_flag zend.ze1_compatibility_mode off
line in .htaccess file but unfortunately I can't do that on server where project is hosted.

I added following line:
Code:
@ini_set('zend.ze1_compatibility_mode', '0');
in index.php but it still doesn't work.

Any ideas?




Theme © iAndrew 2016 - Forum software by © MyBB