2014-12-20 1 views
1

하나의 함수에서 속성에 값을 할당하고 다른 함수에 액세스하려고합니다. 나는 이것이 그렇게 단순해야한다고 생각했다. 불행히도 나는이 간단한 작업을 처리 할 수 ​​없습니다.PHP Codeigniter, 속성 값 할당 및 액세스하기

여기 내 컨트롤러 :

<?php 
class Form_Controller extends CI_Controller { 

    public $current_user; 
    public $pi = 3.14; 

    function index() { 
     $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); 

     $this->form_validation->set_rules('username', 'Username'); 
     $this->form_validation->set_rules('password', 'Password'); 

     if ($this->form_validation->run() == FALSE) { 
      $this->load->view('login_form'); 
     } else { 
      $this->load->model('Admin_Users_Model'); 
      $is_logged_in = $this->Admin_Users_Model->login(); 

      if ($is_logged_in) { 
       $this->load->view('admin_panel/panel'); 
       $this->load->view('admin_panel/account_verification_status_form'); 
      } else { 
       $this->load->view('login_form'); 
      } 
     } 
    } 

    function account_verification() { 

     $this->load->model('User_Id_Model'); 
     $data['user_data'] = $this->User_Id_Model->get_user_credentials(); 

     $this->current_user = $data['user_data']; 

     foreach ($this->current_user as $value) { 
      echo $value; 
     } 

     $this->load->view('admin_panel/panel'); 
     $this->load->view('admin_panel/account_verification_status_form'); 
     $this->load->view('admin_panel/account_verification_name_form', $data); 
     $this->load->view('admin_panel/account_verification_status', $data); 
    } 

    function name_verification() { 

     $selected_value = $this->input->post('verify-name'); 

     echo count($this->current_user) . '<br />'; 

     echo $this->current_user; 
     echo $this->pi; 
     $this->account_verification(); 
    } 

    private function _write_to_database($user_data) { 
     $this->load->model('User_Id_Model'); 
     $this->User_Id_Model->write_to_database($user_data); 
    } 

} 
?> 

내가 account_verification() 전화

$current_user에 값이 할당되고, 나는 그것을 인쇄 할 수 있어요. 그 후에 나는 name_verification()이라고 전화하고 있지만 $current_user에는 가치가 없습니다. 여기에 무슨 일이 일어나는지 아는 경우 설명하십시오. 당신이 전화하는 경우

$this->current_user. 

2), 즉 글로벌 varibale에 어떤 값을 할당하지 않는 것보다 당신이 URL에서 name_varification를 호출하는 경우 코드

1)보고 후 모든

답변

1

처음 URL에서 account_varification 당신은 golbal 변수

$this->current_user 

에 할당하십시오 데이터를 가지고 그렇게 다시 account_varification 내에서 name_varification를 호출하지 않는 것보다 내가 t는 url로부터 호출하고 있다는 것을 의미하므로 값을 잃어 버릴 수 있으므로 적절한 코드는 첫 번째 name_varificaton을 호출하고 다음 데이터를 지정합니다.

$this->load->model('User_Id_Model'); 
    $data['user_data'] = $this->User_Id_Model->get_user_credentials(); 
    $this->current_user = $data['user_data']; 

그 호출 $ this-> account_verification 당신이 값

난 당신이 이해 희망이있을 것이다 두 기능보다 호출하는 등의 후. 감사합니다 Imran Qasim

+0

무슨 뜻인지 모르겠군요. 제발 좀 더 자세히 설명해주세요. 명확히하려면 - 양식이있는보기가 있습니다. account_verification()은 account_verification()을 호출합니다. account_verification()은 또 다른보기를 추가하여 다른 양식을로드합니다. 두 번째 양식이 제출되면 name_verification()이 호출됩니다. account_verification()에서 일부 사용자 자격 증명이 있습니다. $ data [ 'user_data'] = $ this-> User_Id_Model-> get_user_credentials(); 내가하려고하는 일은 두 번째 방법으로 자격 증명을 전달하는 것이므로 두 번째 양식에서받은 값으로 DB의 해당 사용자를 업데이트 할 수 있습니다. – newuser123

+0

두 가지 형식이있는 경우 url을 통해 두 함수를 호출한다는 의미이므로 전역 변수 current_user보다 name_varification 함수를 호출 할 때 값이 유지되지 않습니다. 당신이 그 값을 유지하기를 원한다면, 세션을 사용하여 첫 번째 폼을 제출 한 후에 값을 reatins하고 두 번째 메소드 name_varification을 호출하면 세션에서 그 값을 얻습니다. 그러면이 값이 문제를 해결할 것입니다. –

+0

당신은 실제로 옳습니다. 세션에 추가하면 다음 함수로 전달할 수 있습니다. 나를 위해 남아있는 모든 것은 지금부터해야 할 일을 파악하는 것입니다. X – newuser123