错误:未定义属性:News :: $ code_iterate中的form_validation [英] error: Undefined property: News::$form_validation in codeigniter
问题描述
我是新的codeigniter,并尝试在用户指南中的教程。但我坚持我的第三个教程是为创建新闻项目。这里在我的控制器部分它给出以下错误:
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:
严重性:注意
消息:未定义属性:新闻:: $ form_validation
Message: Undefined property: News::$form_validation
档案名称:controllers / news.php
Filename: controllers/news.php
行号: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');
}
}
请帮助我。
提前感谢。
推荐答案
推荐你不指定加载模型。
Propably you don't specify loading model. So include this before
$this->load->model('news_model');
之后您可以呼叫
$this->news_model->set_news();
或编辑config\autoload.php并设置模型,然后可以成功验证后使用
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');
}
和拨打型号
这篇关于错误:未定义属性:News :: $ code_iterate中的form_validation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!