2017-01-09 1 views
0

에서 모델과 디스플레이에서 값을 가져 오는 방법을 여기 내 컨트롤러, 모델과 뷰입니다 CodeIgniter의에서 사이트를 만드는 중이라서 컨트롤러

보기 :

foreach ($dbemail as $new_dbemail) 
    { 
     echo $new_dbemail['database_field'];//in here you can get your table header. 
    //Ex if your table has name field and you need to sho it you can use $new_dbemail['name'] 
    } 
,321 0 그러나 나는 컨트롤러 대신 $ new_dbemail [ 'name']의 값을 얻을 수있는 $ new_dbemail [ 'name']을 (를) 내 컨트롤러에서 가져오고 싶습니다. ???

답변

0

당신은 변수에 모델을 호출하는이 -

$data['dbemail']=$this->login_model->email(); 

은 그래서 당신은 당신이 데이터베이스에서 가져 오는되는 결과가있다. 이 변수 데이터를보기에 전달하는 것보다.

$this->load->view('home', $data); 

$ data에 저장되어있는 모델에서 가져온 컨트롤러의 값이 이미 있습니다. 컨트롤러에서

...

...

당신은

echo "<pre>"; 
print_r($data); 

를 사용하여, $ 데이터의 값을 볼 수 있으며이 같은 시도

0

을받는 어떤 데이터가 표시됩니다
function checking() 
{ 
$email=$this->input->post('email'); 
$this->load->model('login_model'); 
$dbemail=$this->login_model->email();//array containing all emails 
//For each loop here for displaying emails 
foreach($dbemail as $email){ 
    $mail = $email; //assigning to variable 
    echo $mail."<br/>";//displaying email 
    } 

$data['dbemail'] = $dbemail;//for passing to view 
$this->load->view('home', $data); //passing your value to view 
} 
+1

그건 이상한 코드입니다, 당신은 컨트롤러에서 일을 되풀이하지 않습니다! – jtheman

+0

@jtheman 그는 전자 메일 만 선택하고 컨트롤러에서 전자 메일 값을 가져오고 싶습니다. –

+0

아니 그가 물어 보는 게 아니야. "하지만 내 컨트롤러에서 $ new_dbemail [ 'name']을 (를) 가져 오려면 어떻게해야합니까?보기 대신 컨트롤러에서 $ new_dbemail [ 'name']의 값을 얻을 수있는 방법" - 여전히 - 당신은 CI의 컨트롤러에서 echo()하지 않습니다. 출력을 위해보기를 사용합니다! – jtheman

0

먼저 모델의 데이터베이스에서 이름을 가져와야합니다. 쿼리 줄을 변경 :

$query = $this->db->query("SELECT name, email FROM change_password"); 

그런 다음 당신이 시도 할 수있는 컨트롤러의 이름 데이터를 사용 :

function checking() 
{ 
    $email=$this->input->post('email'); 
    $this->load->model('login_model'); 
    $data['dbemail']=$this->login_model->email(); 
    $name = $data['dbemail']['name']; // example usage to retrieve name in controller 
    $this->load->view('home', $data); 
} 

것은 이제 이름 데이터가 컨트롤러 $name로 사용할 수 있습니다.

0

컨트롤러 :

public function checking() 
{ 
$email=$this->input->post('email'); 
$this->load->model('login_model'); 
$data['dbemails']=$this->login_model->email(); 
$this->load->view('home', $data); //passing your value to view 
} 

모델

public function email() 
{ 
$this->db->select("email"); // the row of the table you want to select. 
$this->db->get('change_password'); //table name. you can still use your query, its just much neat when you use a specific query builder. 
$result = $this->result(); //giving you a result of type object 
return $result; 
} 

보기이 당신을 위해 무엇을 찾고

foreach ($dbemails as $dbemail) 
{ 
    echo $dbemail->email; // the '->' will be the identifier of which row you want to get or display, i assume its email beacause you specify it in the model. 
} 

희망.