2013-10-19 105 views
3
调用未定义功能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调用未定义功能VALIDATION_ERRORS()

<?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'; 

如何解决?不能将数据插入到数据库中,因为致命错误。

回答

9

我看不到你在任何地方加载你的validation_form库 - 你确定它被加载?

无论是在自动加载,否则:

$this->load->library('form_validation'); 
+0

我已经载入自动载入,它的工作... 现在的问题是,当我提交值不存储到数据库。 –

0

我是一个新手,这个整体规划东西。 我想应该有HTML输入字段的标签ID。所以模型中的数组可以读取它们。

Name <input type="text" id="comment_name" name="comment_name"></input><br /> 
Email <input type="text" id="comment_email" name="comment_email"></input><br /> 
Comment<input type="text" id="comment_body" name="comment_body"></input><br />