問題描述
遇到錯誤無法加載請求的文件:helpers/form_validation_helper.php (An Error Was Encountered Unable to load the requested file: helpers/form_validation_helper.php)
登錄頁面在我的項目中不起作用,所以它說
無法加載請求的文件:helpers/form_validation_helper.php
我已經在我的項目的配置文件中加載了提到的文件。但它仍然不起作用。
控制器包含兩個函數auth
函數檢查身份驗證和加載視圖的index
函數
登錄控制器源碼:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function index() {
$this‑>load‑>view('pages/login');
}
function auth() {
$this‑>load‑>helper('form');
$this‑>load‑>helpers('form_validation');
$rules = array(
array(
'field' => 'username',
'label' => 'Username',
'rules' => 'required'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'required'
)
);
$this‑>form_validation‑>set_rules($rules);
if($this‑>form_validation‑>run() == false) {
$this‑>load‑>view('pages/login');
} else {
echo "valid form";
}
}
}
登錄查看源碼:
<body>
<section class="container">
<div class="login">
<h1>Login to Web App</h1>
<?php $this‑>load‑>helper('form');
echo validation_errors();
echo form_open('login/auth');
$username = form_input(array('name'=> 'username', 'placeholder' => 'username or Email'));
$password = form_password(array('name' => 'password', 'placeholder' => 'password'));
$checkbox = form_checkbox('remember', '1');
$submit = form_submit('submit','Login')
?>
<p><?=$username;?></p>
<p><?=$password;?></p>
<p class="remember_me">
<label>
<?=$checkbox;?>
Remember me on this computer
</label>
</p>
<p class="submit"><?=$submit;?></p>
<?php form_close(); ?>
</div>
</section>
</body>
</html>
參考解法
方法 1:
Form validation is not a helper, it is a library:
$this‑>load‑>library('form_validation');
Please correct it.
方法 2:
Actually form_validation is a library, not a helper
so you can use
$this‑>load‑>library('form_validation');
not
$this‑>load‑>helpers('form_validation');
(by Esmatullah、d.coder、Janaka)