php 致命错误:使用 codeIgniter 调用未定义的函数 validation_errors()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19471788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 19:32:30  来源:igfitidea点击:

Fatal error: Call to undefined function validation_errors() using codeIgniter

phpcodeignitercodeigniter-2

提问by Ashish Singh

Fatal error: Call to undefined function validation_errors() using codeIgniter here's my comments.phpview

致命错误:使用 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>

here's my news_model.php

这是我的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);
}

}

}

here my controller news.php

这是我的控制器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');
}   


}

}

}

in routes.php

routes.php

$route['news/comments'] = 'news/comments';

how to resolve ?cannot insert data into database because of fatal error.

如何解决?由于致命错误,无法将数据插入数据库。

回答by jmadsen

I don't see you loading your validation_form library anywhere - are you sure it is loaded?

我没有看到您在任何地方加载您的 validation_form 库 - 您确定它已加载吗?

Either in autoload, or else:

要么在自动加载中,要么:

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

回答by NashguL

I'm a newbie to this whole programming thing. I guess there should be label IDs to the HTML input field. So the array in the model can read them.

我是整个编程的新手。我想 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 />