2012-03-07 16 views
1

コードイグナイタ2.1.0を使用してユーザー登録フォームを設計しようとしています。私はコントローラのregitration.phpに次のコードを使用してユーザーを追加しました。非オブジェクトコードイグナイタのメンバー関数run()を呼び出す

class Registration extends CI_Controller 
{ 

    function __construct() { 
     parent::__construct(); 
    } 


    function index() 
    { 
     $data['main_content'] = 'registration'; 

     // Checks to see if form validation rules were met an executed properly. If not, will return with registration form. 
     if ($this->form_validation->run('registration') === FALSE) 
     { 
      $data ['title'] = 'Registration'; 
      $this->load->view('include/template', $data); 
     } 

     // If validation passes, information will be passed along to the MODEL to be processed and the account will be created. 
     else 
     { 
      $this->load->model('registration_model'); 
      $this->registration_model->addUser(); 

      $this->session->set_flashdata('success', 'Your account has been successfully created'); 
      redirect(uri_string()); 
     } 
    } 
} 

しかし、それは私にCall to a member function run() on a non-objectのエラーを示しました。どのように私はそれを修正するのですか?

+1

$ this-> load-> libraryメソッド( 'form_validation')にこれを追加します。これを含める – Ghostman

+0

私はイグナイタを新しくしました。このコードをどこに置かなければならないのかを教えてください。 – designersvsoft

+0

私の更新された回答を参照してください – Ghostman

答えて

3

// load 'form' helper 
    $this->load->helper('form'); 

    // load 'validation' class 
    $this->load->library('form_validation'); 

を含めてください、今

function __construct() { 



    // load controller parent 
    parent::__construct(); 

    // load 'url' helper 
    $this->load->helper('url'); 

    // load 'form' helper 
    $this->load->helper('form'); 

// load 'session' 
$this->load->library('session'); 
    // load 'validation' class 
    $this->load->library('form_validation'); 

    } 

それが正しく初期化されていない$セッションクラスのように思えるしてみてください。

  1. データベースでセッションを使用している場合は、default_ci_sessionsテーブルを確認します。
  2. コンストラクタがセッションライブラリをロードしているかどうかを確認します。この"In order to use the Session class you are required to set an encryption key in your config file."のために
  3. チェックセッションがautoload.php設定している場合

。 は、あなたのconfig.php

$config['encryption_key'] = 'your_encryption_key_here'; 
+0

これで、次のエラーが表示されます。致命的なエラー:未定義のメソッドを呼び出すCI_Controller :: controller() – designersvsoft

+0

hmmm replace parent :: Controller(); parent :: __ construct();を使用しています。 – Ghostman

+0

@designersvsoft更新された答えを参照してください – Ghostman

関連する問題