繁体   English   中英

未定义的索引:在PHP codeigniter中发送变量时

[英]Undefined index: in PHP codeigniter while sending variable

我的控制器:

public function thread($page = 'empty')
{

    $data['user_id'] = $this->tank_auth->get_user_id();
    $data['username'] = $this->tank_auth->get_username();
    //User data variable grab
    //default template load data
    $data['thread'] = $this->thread_model->get_thread($page);
    $data['title'] = ucfirst($page); // Capitalize the first letter
    $data['replies'] = $this->thread_model->get_reply($data['thread']['thread_id']);
    $this->thread_model->view_increment($data);
    $this->load->view('templates/head', $data);
    $this->load->view('main/wrapper-start', $data);
    $this->load->view('templates/leftbar', $data);
    $this->load->view('main/thread', $data);
    $this->load->view('main/wrapper-end', $data);
    $this->load->view('templates/footer', $data);

}

错误出现在$data['replies']行上:

严重程度:注意

消息:未定义的索引:thread_id

文件名:controllers / main.php

行号:40

这是我答复的模型代码: $this->thread_model->get_reply

public function get_reply($thread_id)
{

    $query = $this->db->query("SELECT r.reply_id FROM reply_thread rt
    INNER JOIN replies r
    ON rt.reply_id = r.reply_id
    WHERE thread_id = ". $thread_id);
    $replies = $query->result_array();
    $replyarray = array();
    foreach ($replies as $reply)
    {
        $id = $reply['reply_id'];
        $query = $this->db->query("SELECT * FROM replies WHERE reply_id='$id'");
        $thisRow = $query->row_array();
        $replyarray[] = $thisRow;
    }

    return $replyarray;
}

任何想法为什么会出现此错误? 除了错误以外,该页面的加载情况还不错……所有信息均完好无损,可通过查询获得。

这是我的get_thread模型

public function get_thread($page)
{
    $slug = $page;
    $query = $this->db->get_where('thread', array('slug' => $slug));
    return $query->row_array();
}

使用print_r($data['thread']); 我得到这个数组:

Array ( [thread_id] => 233 [owner_id] => 8 [subject] => Repercussions of D3 addiction [body] => 1. signs of unhygienic practices 2.become irritable when forced to stop playing 3. carpal tunnel 4. loss of interest in pursuing a significant other 5. sleep deprivation 6. malnutrition There's nothing positive about this. [timestamp] => 2012-05-08 19:03:02 [replystamp] => 2012-05-09 12:38:32 [last_post_id] => 3 [slug] => 233-repercussions-of-d3-addiction [replies_num] => 2 [views] => 21 )

我认为您可以尝试以下方法:

$threadinfo = $this->thread_model->get_thread($page);
$data['thread'] = $threadinfo;
$data['replies'] = $this->thread_model->get_reply($threadinfo->thread_id);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM