Php Json编码问题

Php Json编码问题,php,json,codeigniter,encode,Php,Json,Codeigniter,Encode,出于某种原因,当我提交表单时,它显示消息:json_encode()希望参数2很长,字符串在控制器的这一行给出,但不确定原因。有人知道问题是什么吗 控制器 function forgot_password_submit() { $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean'); if (!$this->form_validation->

出于某种原因,当我提交表单时,它显示消息:json_encode()希望参数2很长,字符串在控制器的这一行给出,但不确定原因。有人知道问题是什么吗

控制器

function forgot_password_submit() 
{
    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');

    if (!$this->form_validation->run()) 
    {
        $this->kow_auth->output('There was a problem submitting the form! Please refresh the window and try again!', FALSE);
        return;
    }

    $user_data = $this->users->get_user_by_username($this->input->post('username'));
    if ($user_data === NULL) 
    {
        $this->kow_auth->output('User does not exist in the database!', FALSE);
        return;
    }

    $already_sent_password = (isset($user_data->new_password_key) && isset($user_data->new_password_requested));
    if ($already_sent_password) 
    {
        $this->kow_auth->output('Check your email for your temporary password!');
        return;
    }

    if (!strtotime($user_data->new_password_requested) <= (time() - 172800)) 
    {
        $this->kow_auth->output('You have to wait 2 days before a new temp password can be emailed!', FALSE);
    } 
    else 
    {
        if ($this->kow_auth->forgot_password($this->input->post('username'))) 
        {
            $this->kow_auth->send_email('forgot_password', 'KOW Manager Forgot Password Email', $user_data);
            $this->kow_auth->output('A temporary password has been emailed to you!');
        } 
        else 
        {
            $this->kow_auth->output('A temporary password could not be created for you!', FALSE);
        }
    }
}

是的,
json_encode
的第二个参数应该是选项的位掩码,而不是消息。一次只能对一件事进行编码,不能对字符串和数组进行编码。也许你想要像
json\u encode(array($status,$message))

这样的东西来代替消息。这太模糊了。您不能使用
json\u encode
,句号以这种方式对消息和状态进行编码。您希望输出是什么?不管消息输出发生了什么,这都是一个完全不同的主题。您应该在视图中真正回显json,这与MVC模式背道而驰。
/**
* Generate output message
*
* @param string
* @return object
*/
function output($message, $success = TRUE) 
{
    $status = $success ? array('succes' => 'yes') : array('error' => 'yes');
    echo json_encode($status, $message);
}