2013-07-23 2 views
1
<< Error message >> 
Severity: Notice 
Message: Uninitialized string offset: 0 
Filename: controllers 
Line Number: 192 

이 오류 메시지가 나타납니다. 아래에는 컨트롤러 및 모델 파일이 있습니다.초기화되지 않은 문자열 오프셋 : 0, 이유는 무엇입니까?

// controller file 
    $user = $this->user_model->getByMail(array('total_mail' => $mail_auth)); 

    if($user = '') 
    { 
     $this->load->helper('url'); 
     redirect('/'); 
    } 
    else if($this->encrypt->decode($user['password']) == $password_auth) // line 192 
    { 
     if($user['verified'] == 'N') 
     { 
      $this->session->set_flashdata('message', 'Wront inputs.'); 
      $this->load->helper('url'); 
      redirect('/'); 
     } 
    } 
    else 
    { 
     $this->session->set_flashdata('message', 'Wrong inputs'); 
     $this->load->helper('url'); 
     redirect('/'); 
    } 

} 
    // model file 
function getByMail($option) 
{ 
    $basic_result = $this->db->get_where('ndd_user', array('total_mail' => sanitizeMySQL($option['total_mail']))); 
    if ($basic_result->num_rows() > 0) 
    { 
     $result = $basic_result->row_array(); 
     return $result; 
    } 
    else 
    { 
     return ''; 
    } 
} 

모델 파일에는 쿼리 결과의 배열을 출력하는 getByEmail 함수가 있습니다. 그러나 오류가 발생합니다. 어떻게해야합니까? 사전 :

+0

'line 192'의 위치를 ​​알려주시겠습니까? – guessimtoolate

+0

각주 "// 192"를 추가했습니다. – nextdoordoc

+4

제 내기는'if ($ user = '')'- 빈 문자열 값을'$ user'에 할당하기 때문에 당신이 else에 있는지 검사 할 때입니다. 아마도'if ($ user == '')'를 의미했을 것입니다. – guessimtoolate

답변

3

당신은 if($user = '')

를 할당에

덕분에 적어도 (이것은 을 비어 당신이 테스트하기 전에 몇 가지 문자열의 첫 번째 문자를 얻으려고 코드에서 어딘가에

if($user == '') 
+2

guessimtoolate가이 대답에 대한 신뢰를받을 자격이 있습니다. ... – BLaZuRE

+0

@BLaZuRE 내가 타이핑하는 동안 그는 동의합니다. – bansi

+0

하지만 크레딧을 줄 수있는 방법은 없습니다. 그는 단지 코멘트를 써야하기 때문에 .. – nextdoordoc

1

해야합니다 또는 그렇지 않은 상태에서 배열로 사용하고 싶지만 경고를 먼저 내 보냅니다.)

$foo = ''; 

// these throws "Notice: Uninitialized string offset: 0" 
$firstChar = $foo[0]; 
$firstChar = $foo{0}; 

// this throws "Warning: Illegal string offset 'bar'" 
// and "Notice: Uninitialized string offset: 0" 
$bar = $foo['bar']; 
관련 문제