Php 如何将阵列从控制器发送到视图

Php 如何将阵列从控制器发送到视图,php,arrays,codeigniter,Php,Arrays,Codeigniter,我在控制器中有一个数组,我必须将它发送到视图,然后显示值 控制器页面代码 public function showbookedmenu(){ $rowLength=$this->input->post('rowno'); $check=$this->input->post('checkeed'); $j=0; for($i=1;$i<=$rowLength;$i++) { $check=$this->input

我在控制器中有一个数组,我必须将它发送到视图,然后显示值

控制器页面代码

 public function showbookedmenu(){

 $rowLength=$this->input->post('rowno');
 $check=$this->input->post('checkeed');

    $j=0;
    for($i=1;$i<=$rowLength;$i++)
    {
        $check=$this->input->post('checkeed'.$i);

        if($check== "checked")
        {
        $orderedItem[$j][$i]   = $this->input->post('txtMenuItem'.$i);
        $orderedItem[$j][$i+1]  = $this->input->post('quantity'.$i);
        $orderedItem[$j][$i+2]    = $this->input->post('lebPrice'.$i); 
        $orderedItem[$j][$i+3]= $this->input->post('grandtotal'.$i); 
        $j++;
        }
        else{}
    }
    $data['order']= $orderedItem;
    $this->load->view('orderpage', $data);
 }
公共函数showbookedmenu(){
$rowLength=$this->input->post('rowno');
$check=$this->input->post('checked');
$j=0;
对于($i=1;$iinput->post($checked'.$i));
如果($check==“checked”)
{
$orderedItem[$j][$i]=$this->input->post('txtMenuItem'$i);
$orderedItem[$j][$i+1]=$this->input->post('quantity'.$i));
$orderedItem[$j][$i+2]=$this->input->post('lebPrice'.$i);
$orderedItem[$j][$i+3]=$this->input->post('grandtotal'.$i);
$j++;
}
else{}
}
$data['order']=$orderedItem;
$this->load->view('orderpage',$data);
}
查看页面

 public function showbookedmenu(){

 $rowLength=$this->input->post('rowno');
 $check=$this->input->post('checkeed');

    $j=0;
    for($i=1;$i<=$rowLength;$i++)
    {
        $check=$this->input->post('checkeed'.$i);

        if($check== "checked")
        {
        $orderedItem[$j][$i]   = $this->input->post('txtMenuItem'.$i);
        $orderedItem[$j][$i+1]  = $this->input->post('quantity'.$i);
        $orderedItem[$j][$i+2]    = $this->input->post('lebPrice'.$i); 
        $orderedItem[$j][$i+3]= $this->input->post('grandtotal'.$i); 
        $j++;
        }
        else{}
    }
    $data['order']= $orderedItem;
    $this->load->view('orderpage', $data);
 }

代码是什么???

首先尝试在视图文件中打印数组值

print_r($order);
如果天气好的话

你可以穿上它

foreach ($order as $value):

并使用它:

首先尝试在视图文件中打印数组值

print_r($order);
如果天气好的话

你可以穿上它

foreach ($order as $value):

然后使用它:

首先重写控制器操作,如下所示:

public function showbookedmenu()
{
  $rowLength = $this->input->post('rowno');    
  $orderedItem = array();

  for($i = 1; $i <= $rowLength; $i++)
  {
    $check = $this->input->post('checkeed'.$i);

    if($check == "checked")
    {
      $orderedItem[] = array(
        'menu_item' => $this->input->post('txtMenuItem'.$i),
        'quantity' => $this->input->post('quantity'.$i),
        'leb_price' => $this->input->post('lebPrice'.$i),
        'grand_total' => $this->input->post('grandtotal'.$i)
      );
    }
  }

  $data['order'] = $orderedItem;
  $this->load->view('orderpage', $data);
}
公共函数showbookedmenu()
{
$rowLength=$this->input->post('rowno');
$orderedItem=array();
对于($i=1;$i input->post('checkeed'.$i));
如果($check==“checked”)
{
$orderedItem[]=数组(
“菜单项”=>$this->input->post('txtMenuItem'.$i),
“数量”=>$this->input->post('quantity'.$i),
“leb_price”=>$this->input->post('lebPrice'.$i),
“总计”=>$this->input->post('grandtotal'.$i)
);
}
}
$data['order']=$orderedItem;
$this->load->view('orderpage',$data);
}
在您看来,您可以这样做:

<? foreach($order as $order_item): ?>
  <? echo $order_item['menu_item']; ?>
  <? echo $order_item['quantity']; ?>
  <? echo $order_item['leb_price']; ?>
  <? echo $order_item['grand_total']; ?>
<? endforeach; ?>

首先重写控制器操作,如下所示:

public function showbookedmenu()
{
  $rowLength = $this->input->post('rowno');    
  $orderedItem = array();

  for($i = 1; $i <= $rowLength; $i++)
  {
    $check = $this->input->post('checkeed'.$i);

    if($check == "checked")
    {
      $orderedItem[] = array(
        'menu_item' => $this->input->post('txtMenuItem'.$i),
        'quantity' => $this->input->post('quantity'.$i),
        'leb_price' => $this->input->post('lebPrice'.$i),
        'grand_total' => $this->input->post('grandtotal'.$i)
      );
    }
  }

  $data['order'] = $orderedItem;
  $this->load->view('orderpage', $data);
}
公共函数showbookedmenu()
{
$rowLength=$this->input->post('rowno');
$orderedItem=array();
对于($i=1;$i input->post('checkeed'.$i));
如果($check==“checked”)
{
$orderedItem[]=数组(
“菜单项”=>$this->input->post('txtMenuItem'.$i),
“数量”=>$this->input->post('quantity'.$i),
“leb_price”=>$this->input->post('lebPrice'.$i),
“总计”=>$this->input->post('grandtotal'.$i)
);
}
}
$data['order']=$orderedItem;
$this->load->view('orderpage',$data);
}
在您看来,您可以这样做:

<? foreach($order as $order_item): ?>
  <? echo $order_item['menu_item']; ?>
  <? echo $order_item['quantity']; ?>
  <? echo $order_item['leb_price']; ?>
  <? echo $order_item['grand_total']; ?>
<? endforeach; ?>


Hello orderpage是视图页面名称而不是数组此是CodeIgniter:传递到视图的数据将以
$order
的形式存在,而不是以
$data
的形式存在。Hello orderpage是视图页面名称而不是数组此是CodeIgniter:传递到视图的数据将以
$order
的形式存在。请打印($order)在您的视图中,查看输出?是否打印($order)在您的视图中,查看输出?