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

时间:2014-03-19 10:00:17

标签: php codeigniter

错误是致命错误:在第5行的C:\ xampp \ htdocs \ payroll \ application \ views \ dtr_timerecord_overtime.php中调用未定义的函数validation_errors()。

我试图将错误消息发送到其他视图,这没关系,但是当我尝试原始视图时总是出错

查看

<table border="0">

        <tr>
            <tr>
                <td> <?php echo validation_errors(); ?> </td?
            </tr>
        <tr>
            <td align=""><label>OT APPLICATION NO</label></td>
            <td>
            <input type="text" id="txtOtApplication" name="txtOtApplication" />
            </td>
            <td align="right"><label>DATE</label></td>
            <td align="right"><input id="labelDateTodayOvertime" disabled/></td>
            <td colspan="2">
            <input type="hidden" id='txtDateTodayOvertime' name="txtDateTodayOvertime"/>
            </td>
        </tr>
            <tr>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td align=""><label>DESCRIPTION</label></td>
            <td colspan="5">
            <input type="text" id="txtDescription" name="txtDescription" />
            </td>
        </tr>
            <tr>
            <td>
                &nbsp;
            </td>
        </tr>

        <tr align="center">
            <td><label>EMPLOYEE</label></td>
            <td><label>DATE</label></td>
            <td><label>TIME FROM</label></td>
            <td><label>TIME TO</label></td>
        </tr>
        <tr>

    <div id="OVERTIME_ADDLINE-div" on>
        <div>
            <td>
            <input type="text" id="txtEmployee" name="txtEmployee" size="30"/>
            </td>
            <td>
            <input type="date" id="txtDate" name="txtDate" />
            </td>
            <td>
            <input type="time" id="txtTimeFrom" name="txtTimeFrom" />
            </td>
            <td align="center">
            <input type="time" id="txtTimeTo" name="txtTimeTo" />
            </td>
            <td>
            <input type="button" id="btnAddLine" name="btnAddLine" value="ADD LINE" />
            </td>

            </div>
        </div>

        </tr>
            <tr>
            <td>
                &nbsp;
            </td>
        </tr>


        <tr align="center">
            <td>
            <input type="submit" name="btnSaves" value="SAVE AND SUBMIT">
            </td>
            <td>
            <input type="button" name="btnReset" value="RESET" onclick='ClearFields();'>
            </td>
            <td>
            <input type="button" name="btnGenerate" value="GENERATE">
            </td>
        </tr>
    </table>

控制器

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dtr_controller extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
    }
public function saveovertime(){

        $this->load->library('form_validation');
        $this->form_validation->set_rules('txtOtApplication', 'Overtime Application No.', 'required');
        $this->form_validation->set_rules('txtDescription', 'Description', 'required');
        $this->form_validation->set_rules('txtEmployee', 'Employee', 'required');
        $this->form_validation->set_rules('txtTimeFrom', 'Time From', 'required');
        $this->form_validation->set_rules('txtTimeTo', 'Time to', 'required');
        $this->form_validation->set_rules('txtDate', 'Date', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('dtr_timerecord_overtime');
        }
        else
        {   
        $this->load->model('dtr_model');
        $this->dtr_model->saveovertime();
        $this->load->view('success_overtime');

        }

    }   
}

模型

class Dtr_model extends CI_Model {

    public function __construct(){
            parent::__construct();

    }

    function saveovertime(){
        $value = array(
                        'OT_APPLICATION_NO'=>$this->input->post('txtOtApplication'),
                        'DESCRIPTION'=>$this->input->post('txtDescription'),
                        'DATETODAY'=>$this->input->post('txtDateTodayOvertime'));

        $query = $this->db->insert('dtr_timerecord_overtime',$value);
        $value = array(
                        'EMPLOYEE'=>$this->input->post('txtEmployee'),
                        'TIME_FROM'=>$this->input->post('txtTimeFrom'),
                        'TIME_TO'=>$this->input->post('txtTimeTo'),
                        'DATE'=>$this->input->post('txtDate')); 
        $query = $this->db->insert('dtr_timerecord_overtime_line',$value);  
    }
}

3 个答案:

答案 0 :(得分:2)

好的,这是我的解决方法:

首先,我在我的视图中有这个:

<?php
    echo validation_errors();
?>

它没有用。我一直收到致命错误:调用未定义的函数validation_errors() ......

然后我这样做了:

<?php
    $this->load->library('form_validation');
    echo validation_errors();
?>

它有效!

答案 1 :(得分:0)

您尚未在form_helper中加载application\config\autoload.php,请在自动加载文件中加载form帮助

或在控制器上

$this->load->helper("form");

validation_errors()函数是表单助手。

答案 2 :(得分:0)

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

在控制器的构造函数中写这个,或者更好地自动加载它。也许,在该方法中,您发布此表单,您不小心没有加载表单验证库