doudi5892 2014-02-16 20:52
浏览 48
已采纳

控制器查看传递数组

So I have this line of code in my controller:

$this->load->view('sampleview',$result);

So when I go into my view and try to echo result, either by foreach or directly writing

print_r($result);

it shows an error that it is an undefined variable.

But when I put the print_r($result); on my controller like this below:

function show()
{
$this->load->view('sampleview',$result);
print_r($result);
}

It would print on my sampleview page where I was redirected. I’m confused why this is happening.

EDIT

The whole controller would be: I have another view which I click an anchor tag with segment(3) as an id. Then I query that id to my model then pass it to another view for display.

$id = $this->uri->segment(3);
$result = $this->model->show($recipe_id);
        if($result!=null)
        {   
            $this->load->view('Admin_recipe_edit',$result);
        }
  • 写回答

4条回答 默认 最新

  • donglong2856 2014-02-16 20:54
    关注

    You $result array will be extracted in your view. if you want as an array, then do it as

    $data["result"] = $result;
    $this->load->view('sampleview',$data);
    

    Then do print_r($result); in view.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部