Search code examples
phpformscodeigniter

There is a error in my form_validation in code igniter 3 it has a red line under it when i hover my mouse on in it says unindentified property


I already added it to my autoload

 $autoload['libraries'] = array('form_validation','session', 'pagination');
          $autoload['helper'] = array('url','form','text');

Here is the controller code where I am going to use the set_rules function on my form validation.

public function register()
              {
                   $this->load->library('form_validation');
                   $this->form_validation->set_rules('first_name','First Name','trim|required|alpha');
              }

tried re-adding the form_validation to the autoload libraries

I don't really know what to do at this point currently a newbie at using code igniter.


Solution

  • You're getting that error because your controller and its parent classes do not have a form_validation property in their source code.

    If you look at the source code for CI_Controller (your controller should be extending CI_Controller) you can see that this is true, but CI_Controller also allows you to load libraries via its load property.

    When you call $this->load->library('form_validation') this then (during script execution) creates a new property on CI_Controller for the library you've requested (form_validation in this case), which you can then use.

    But since this property is added dynamically and is not in the source code, your code editor can't know about it, thinks you're making a mistake and gives you the error.

    So you can ignore the error in this case, your code should work!