如何将值从视图传递给控制器

时间:2014-01-29 10:46:56

标签: php mysql codeigniter

这是我的控制器代码

$data['query']= $this->webpages->get_where_custom('parent_id',0); 
// i  will get $id from view 
$data['query']=$this->webpages->get_where_custom('parent_id',$id);

$this->load->view-(template,$data);

在视图代码中,我将$ id发送给控制器,但它显示未定义的变量'id'

   <?php

   foreach($query->result() as $row){
       $id=$row->id;   // how to send this $id to my controller
       $page_url=$row->page_url;
       $parent_id=$row->parent_id;
       $page_headline=$row->page_headline;

  foreach($query->result() as $row){
       $page_url=$row->page_url;
       $page_headline=$row->page_headline;

  ?>
  echo $page headline;
  }

}

2 个答案:

答案 0 :(得分:0)

而不是:

$this->load->view-(template,$data);

陷阱>

$this->load->view(template,$data);

答案 1 :(得分:0)

您的代码看起来像这样

$this->load->view('template',$data);

这是因为你没有在你提出查询的数据中加上$ id

所以<?php print_r($query); ?>