致命错误:使用 codeIgniter 调用未定义函数 validation_errors() 这是我的comments.php视图
<?php echo validation_errors(); ?>
<?php echo form_open('news/comments'); ?>
Name <input type="text" name="comment_name"></input><br />
Email <input type="text" name="comment_email"></input><br />
Comment<input type="text" name="comment_body"></input><br />
<input type="submit" name="submit" value="Comment it" ></input>
</form>
这是我的news_model.php
<?php
class News_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
//set comment
public function set_comment()
{
$this->load->helper('url');
$this->load->helper('date');
$data_c = array(
'comment_name' => $this->input->post('comment_name'),
'comment_email' => $this->input->post('comment_email'),
'comment_body' => $this->input->post('comment_body'),
);
return $this->db->insert('comments', $data_c);
}
}
这是我的控制器news.php
<?php
class News extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('news_model');
}
public function create_comment()
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('comment_name', 'comment_name', 'required');
$this->form_validation->set_rules('comment_email', 'comment_email', 'required');
$this->form_validation->set_rules('comment_body', 'comment_body', 'required');
if ($this->form_validation->run() === FALSE)
{
echo 'failed'; //just for debugging
}
else
{
$this->news_model->set_comment();
$this->load->view('news/success');
}
}
}
在routes.php中
$route['news/comments'] = 'news/comments';
如何解决?由于致命错误,无法将数据插入数据库。