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.

So may i know what causes error in the server. 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';

        $this->validation->set_rules($rules);

        $fields['admin_name']        = $this->lang->line('login_username');

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

Output:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Sample::$validation

Filename: admin/sample.php

Line Number: 23

Can any one guide me on how to fix this issue. Please help me.
#2

[eluser]Shahgeb[/eluser]
load library fo validation in constructor not in index function
#3

[eluser]Prasanna[/eluser]
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.

The same problem occurs while loading some models.

Also we have completed project in the way i have given. So any please provide any alternative solution for the problem.
#4

[eluser]Shahgeb[/eluser]
for this purpose you have load library in that paricular function than it will work.
reason have mentioned in user guide in codeignitor.
fine
hope you got
#5

[eluser]xwero[/eluser]
What is line 33? I just tried your code but without the fields part and it worked.
#6

[eluser]Shahgeb[/eluser]
for loading modle you are facing same problem. try to solve it yourself
#7

[eluser]janogarcia[/eluser]
Prasanna, check your system/logs directory, maybe the validation library is being loaded automatically by another library that you specified in autoload.php ie: Session class with sess_encrypt_cookie set to TRUE (This led me once to a bug when the user was idle for a time longer than sess_expiration)

Look for this line in your logs
Code:
Validation Class Initialized

If that's your case, check which library is loading it and under which circumstances.
#8

[eluser]Prasanna[/eluser]
I have updated my post as the line number i have specified is wrong. Now it's perfect.
#9

[eluser]xwero[/eluser]
Couldn't you just add a comment this line is the problem Smile So it's the line were you add the field. Are you sure the login_username is loaded in the language library? you can check it using
Code:
print_r($this->lang->language);
#10

[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




Theme © iAndrew 2016 - Forum software by © MyBB