2014-02-19 5 views
0

안녕하세요 : 선택 상자의 코드 점화기에서 데이터베이스의 콘텐츠를 표시하고 싶습니다. 데이터베이스에서 콘텐츠를 수신 할 수 없습니다. 도우미로 어떻게 표시합니까? 도우미를 사용하면 다음과 같은 오류가 발생합니다. 어떻게 똑같이 할 수 있지.헬퍼에서 데이터베이스의 내용을 얻는 방법

Fatal error: Using $this when not in object context in G:\xampp\htdocs\lokalpickup_ci\admin\application\helpers\lib_helper.php on line 79 
+1

이 오류가 발생하는 코드를 추가하십시오. –

답변

0

문제는 $ this를 사용하고 있습니다. 실제로 도우미에서는 CodeIgniter에서 $ this를 사용할 수 없습니다. 인스턴스를 변수로 가져와 $ this와 같이 사용할 수 있어야합니다.

$CI = & get_instance(); 
    $CI->load->model('Dynamic_dropdown', 'dd_model'); 

아래 코드는 PHP 코드 생성기에서 생성 한 동적 선택 컨트롤입니다. 이런 식으로 사용할 수 있습니다.

function form_dynamic_dropdown($tablename, $fieldDetails, $valueColumn, $displayColumn, $default='') { 
     if (!is_array($fieldDetails)) { 
      log_message('error', 'Field details should be an array for dynamic dropdown', TRUE); 
      return; 
     } 
     $field_properties = '<select'; 
     foreach ($fieldDetails as $key => $value) { 
      $field_properties .= ' ' . $key . ' = \'' . $value . '\''; 
     } 
     $field_properties .= '>'; 

     $CI = & get_instance(); 
     $CI->load->model('Dynamic_dropdown', 'dd_model'); 
     $field_properties .= '<option value=\'\'>'; 
     $field_properties .= 'Select'; 
     $field_properties .= '</option>'; 

     if(isset($fieldDetails['name']) && isset($_POST[$fieldDetails['name']])) 
      $default = $_POST[$fieldDetails['name']]; 

     $condition = array(); 
     $results = $CI->dd_model->search($condition, $tablename); 
     foreach ($results as $result) { 
      if ($result->$valueColumn == $default) 
       $field_properties .= '<option value=\'' . $result->$valueColumn . '\' selected>'; 
      else 
       $field_properties .= '<option value=\'' . $result->$valueColumn . '\'>'; 
      $field_properties .= $result->$displayColumn; 
      $field_properties .= '</option>'; 
     } 
     $field_properties .= '</select>'; 
     return $field_properties; 
    } 
관련 문제