Part of the EllisLab Network
   
 
[Solved] - Problem in loading Validation Library
Posted: 16 October 2008 09:44 AM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  19
Joined  02-02-2007

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

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

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

//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 ?

<?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);
    
}
}
?>
Profile
 
 
Posted: 17 October 2008 04:30 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  13
Joined  09-16-2008

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.

Profile
 
 
Posted: 17 October 2008 06:01 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  353
Joined  03-31-2007

The validation should work as you have the code, however, try:

<?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);
    
}
}
?>
Profile
 
 
Posted: 06 November 2008 12:05 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  19
Joined  02-02-2007

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://codeigniter.com/forums/viewthread/52308/P15/#450647

Profile
 
 
Posted: 18 August 2009 10:05 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  4
Joined  08-18-2009

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

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:

@ini_set('zend.ze1_compatibility_mode', '0');

in index.php but it still doesn’t work.

Any ideas?

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 721, on January 06, 2010 09:38 AM
Total Registered Members: 115027 Total Logged-in Users: 66
Total Topics: 122466 Total Anonymous Users: 3
Total Replies: 647381 Total Guests: 458
Total Posts: 769847    
Members ( View Memberlist )