遇到錯誤無法加載請求的文件: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 (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 Esmatullahd.coderJanaka)

參考文件

  1. An Error Was Encountered Unable to load the requested file: helpers/form_validation_helper.php (CC BY‑SA 2.5/3.0/4.0)

#php-5.5 #PHP #codeigniter-3






相關問題

當作為參數傳遞時,PHP 如何解釋和評估函數和匿名函數? (How does PHP interpret and evaluate function and anonymous function when passed as an argument?)

使用 symfony 時 PHP 5.5 無法識別服務器 (PHP 5.5 won't recognise server when using symfony)

升級到 PHP5.5 時 Wordpress 崩潰 (Wordpress crashes when upgrading to PHP5.5)

從數據庫返回多個值 (return multiple values from database)

PHP:嵌套 foreach 循環的問題 (PHP: Issue with nested foreach loops)

如果條件在幾小時、幾天內不起作用 (if condition not working for Hours,Days)

Slim 3.3 輸出中缺少字符 (Slim 3.3 missing characters in output)

PHP排序對象值但保留原始相對順序 (PHP sort objects value but retain original relative order)

遇到錯誤無法加載請求的文件:helpers/form_validation_helper.php (An Error Was Encountered Unable to load the requested file: helpers/form_validation_helper.php)

如何從類的函數內部訪問全局變量 (How to access global variable from inside class's function)

如何修改輸出緩衝區? (How to modify output buffer?)

在同一台 Ubuntu 服務器上安裝和配置 PHP5 和 7 (Install and configure PHP5 and 7 on same Ubuntu server)







留言討論