2017-03-19 43 views
0

這裏我有一個幫手文件。我正在使用此幫助程序文件進行會話登錄。使用這個幫手,我可以靜態獲取值。但我想動態獲得價值。意味着我想將價值從控制器傳遞給幫手。如何將值傳遞給自定義助手。

這裏是我的助手代碼

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

      if (! function_exists('get_user_details')){ 
        function get_user_details($user_id){ 
         //get main CodeIgniter object 
         $ci =& get_instance(); 

         //load databse library 
         $ci->load->database(); 


         //get data from database 
         $query = $ci->db->get_where('user_profile',array('id'=>$user_id)); 

         if($query->num_rows() > 0){ 
          $result = $query->row_array(); 

          return $result; 
         }else{ 
          return false; 
         } 
        } 
      } 

    ?> 

這裏是控制器代碼

function index(){ 
$this->load->helper('login'); 
    $id = 1; 
    get_user_details($id); 

} 
+0

你有沒有做過任何故障排除?如果是這樣,究竟是什麼? – Sparky

回答

2

在你controller嘗試這樣的..

function index(){ 
$this->load->helper('login'); 
    $id = 1; 
    $data = get_user_details($id); 
    if($count($data)>0) 
     { 
     print_r($data); //prints array of records 
     } 
    else{ 
     echo "No record found!!"; 
     } 

} 
相關問題