1
Controller:

    $sid = $this->uri->segment(4);
    $serial = $this->contract_items->get_all_serial($id);
    $_items = array();
        foreach ($serial as $k => $v) {
            $oldserial =  $this->contract_items->get_childrens($sid);
            $_items[$v->contract_id] = array("children" => $oldserial);
        }
    $this->data['serial_items'] = $_items;
    $this->build_view("contracts/serial.php");

这是我 print_r() 时的输出,我希望它在我看来打印“FDO1643R26G”和“FDO1643R26G”。

Array ( [0] => Array ( [children] => Array ( [0] => stdClass Object ( [serial_num] => FDO1643R26G-XXX ) [1] => stdClass Object ( [serial_num] => FDO1643R26G-XXX-XXX ) ) ) )
4

1 回答 1

1

您可以将关联数组中的数据传递给来自控制器的视图。在您的情况下,只需将您的数组分配给数组中的一个键,然后传递它:

$data['_items'] = $_items;

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

// in the view, you can access the array
// in $_items
于 2013-09-23T07:19:26.933 回答