error: Undefined property: News::$form_validation in codeigniter

老子叫甜甜 提交于 2019-12-11 13:46:12

问题


I am new to the codeigniter and trying the tutorials in the user guide. But i stuck i the third tutorial which is for the create news items. Here in my controller section it is giving the following error:

Severity: Notice

Message: Undefined property: News::$form_validation

Filename: controllers/news.php

Line Number: 44

and the code that i used in the controller section is

public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');

$data['title'] = 'Create a news item';

$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('text', 'text', 'required');

if ($this->form_validation->run() === FALSE)
{
    $this->load->view('templates/header', $data);   
    $this->load->view('news/create');
    $this->load->view('templates/footer');

}
else
{
    $this->news_model->set_news();
    $this->load->view('news/success');
}
}

Please help me.

Thanks in advance.


回答1:


Propably you don't specify loading model. So include this before

$this->load->model('news_model');

after that you can call

$this->news_model->set_news();

or edit config\autoload.php and set your model, then you can use after successfully validation

news_model::set_news();

or you can that in constructor, like this:

class MySomeClas extend CI_Controller
 {
  parent::__construct();
  $this->load->model('news_model');
 }

and call models right



来源:https://stackoverflow.com/questions/14116920/error-undefined-property-newsform-validation-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!