未定义的属性:Mahasiswa :: $ form_validation
我已经加载了表单帮助程序和表单验证库。
我正在使用CodeIgniter 3.1.10
。
class Mahasiswa extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Mahasiswa_model');
$this->load->helper('form');
$this->load->library('form_validation');
}
public function index()
{
$data['judul'] = 'Data Mahasiswa';
$data['mahasiswa'] = $this->Mahasiswa_model->getAllMahasiswa();
$this->load->view('templates/header', $data);
$this->load->view('mahasiswa/index');
$this->load->view('templates/footer');
}
public function tambah()
{
$data['judul'] = "Form Tambah Data Mahasiswa";
$this->form_validation->set_rules('nama', 'Nama', 'required');
if ( $this->form_validation->run() == FALSE )
{
$this->load->view('templates/header', $data);
$this->load->view('mahasiswa/tambah');
$this->load->view('templates/footer');
}
else
{
$this->load->view('templates/header', $data);
$this->load->view('mahasiswa');
$this->load->view('templates/footer');
}
}
}
遇到PHP错误 严重程度:通知
消息:未定义的属性:Mahasiswa :: $ form_validation
文件名:controllers / Mahasiswa.php
行号:26
答案 0 :(得分:1)
您应在autoload.php中的config文件夹中添加form_validation库。因为我也遇到了同样的问题,并且对我有用
$autoload['libraries'] = array('form_validation');
答案 1 :(得分:0)
首先,您应该在config文件夹中的autoload.php中加载库。像这样
$autoload['libraries'] = array('form_validation);
$autoload['helper'] = array('url', 'file');