2
<< Error message >>
Severity: Notice
Message: Uninitialized string offset: 0
Filename: controllers
Line Number: 192

这是我遇到的错误消息。以下是控制器和模型文件。

// 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 函数,它输出查询结果数组。但是它会出错。我能怎么做?

提前致谢 :)

4

2 回答 2

3

你分配if($user = '')

至少它必须是

if($user == '') 
于 2013-07-23T07:50:51.923 回答
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'];
于 2013-07-23T08:03:13.037 回答