简体   繁体   中英

$this->form->validation->set_rules(); fails in CodeIgniter

I have form_validation library loaded in my config:

$autoload['libraries'] = array('database','session','form_validation');

And I have next method in one of my Controllers:

public function add(){
        //Validation Rules
        $this->form->validation->set_rules('title','Title','trim|required|max_length[4]|xss_clean');
        $this->form->validation->set_rules('body','Body','trim|required|xss+clean');
        $this->form->validation->set_rules('is_published','Publish','required');
        $this->form->validation->set_rules('category','Category','required');
         //
         //
         //
        }

        }

And it gives me next error:

Fatal error: Call to a member function set_rules() on null

It feels like it's not working because form_validation library is not loaded, but it's auto loaded in config, I've also tried to load it directly in controllers constructor, and it didn't help.

What can be causing the error?

您正在尝试访问$this->form->validation而不是$this->form_validation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM