2017-03-08 17 views
1

私はcodeigniterバリデータを使用してフォームを検証しようとしていますが、これは奇妙なエラーを示していますか? enter image description hereCodeigniterフォームの検証未定義のプロパティ

私はなぜそれが未定義のプロパティを投げるでしょう

$autoload['helper'] = array('url', 'form','text'); 
$autoload['libraries'] = array('form_validation', 'session'); 

をフォームバリデータライブラリやヘルパーを自動的にロードしていますか? は、ここで私は正確に間違っdoignています何私のコントローラ

<?php 
class User extends CI_Controller 
{ 
public function register() 
{ 
    //fields username,email,password1,password2 
    // $this->load->view('templates/header'); 
    // $this->load->view('user/register'); 
    $this->form_validation->set_rules('username','Username','required|max_length[50]|is_unique[users.username]|trim|alpha_numeric'); 
    $this->form_valdiation->set_rules('email','Email', 'trim|required|valid_email|is_unique[users.email]'); 
    $this->form_validation->set_rules('password1', 'Password', 'trim|required'); 
    $this->form_validation->set_rules('password2','Confirm password','trim|required|matches[password1]'); 
    if($this->validation->run === false) 
    { 
     $this->load->view('templates/header'); 
     $this->load->view('user/register'); 
    } else { 

    } 
} 

} のですか?あなたは

$this->validation->run 

を持って

+0

クラスコンストラクタ内に、またはコントローラメソッド内に依存関係を含める必要があります。 – Kaylined

+0

あなたのライブラリは 'CI_Controller'を拡張していますか?そうでない場合は、親クラスから固有のものにする必要があります。 – Kisaragi

+0

@ Kaylinedはまだ動作しませんでした:X。きららぎ申し訳ありませんが、どういう意味ですか? –

答えて

2

をお試しください:

$this->form_valdiation->set_rules 

それはでなければなりません:

$this->form_validation->run() 

はそれがheplsホープ:form_validation

はまた、あなたは()検証関数を呼び出す必要があります。

+0

ああ私の神私はとてもダムです..ありがとう笑 –

0

あなたは二番目のルールにタイプミスがあり

if($this->form_validation->run() == false) 

コントローラexample

そして

public function __construct() { 
    parent::__construct(); 
    $this->load->library('form_validation'); 
} 
+0

まだまだ動作しませんこれはとても変です.. –

+0

ファイル名はuser.phpではありません。 – user4419336

+0

はありません。私はとても笑っていません –

関連する問題