0

これが私のコントローラーです:

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

class User extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('user_model');
    }

    public function index() {
        redirect('user/login');
    }

    public function login() {
        $this->load->library('form_validation', '', 'fv');
        var_dump($this);
        $this->fv->set_rules('nick_name', 'Nick Name', 'trim|required|max_length[12]|min_length[4]');
        $this->fv->set_rules('password', 'Password', 'trim|required|md5');
    }
}
?>

私は基本的にログインコントローラーを書いていました。ログイン機能では、この後、ビューなどをロードします。しかし、ここまで、次のエラーが発生しています。

A PHP Error was encountered
Severity: Notice
Message: Undefined property: User::$fv
Filename: controllers/user.php
Line Number: 23

コントローラー内の他のすべてを、上に貼り付けたものに効果的にコメントアウトしました。問題がどこにあるのかわかりません。ありがとう。

[編集]

$this オブジェクトを var ダンプすると、さらに珍しいことがわかりました。オブジェクト "fv" は、$this オブジェクト内ではなく、$this->user_model オブジェクトの下で定義されました。そのため、isset($this->fv) は false を返し、isset($this->user_model->fv) は true を返していました。はい、「fv」という名前を付ける代わりに $this->load->library('form_validation') を試しましたが、結果は同じままでした。

4

1 に答える 1

0

コントローラー名は user.php という名前にする必要があり、コントローラーフォルダー内に配置する必要があります。

次のような CI 推奨のコーディング スタイルを試してください。

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

$this->form_validation->set_rules(); 等..

于 2012-10-06T09:52:27.237 に答える