ordercontroller.php
$link = 'http://api.amid.tech/alldata/0';
$viewdata = (array)json_decode(file_get_contents($link)) ;
$viewordernames=$viewdata['orders'][0];// here we are just showing admin table
$this->orderId=$viewdata['orders'][0];
$this->orderSerial=$viewdata['orders'][0];
$viewdata=array(
$viewdata['id']=> 'id',
$viewdata['orderSerial']=> 'orderSerial',
$viewdata['order_place_by']=> 'order_place_by',
$viewdata['afterDisAmount']=> 'afterDisAmount',
$viewdata['grandTotal']=> 'grandTotal',
$viewdata['actual_price']=> 'actual_price',
$viewdata['customerId']=> 'customerId',
$viewdata['customerId']=> 'customerId',
$viewdata['createdAt']=>'createdAt'
);
我想在我的视图中显示变量
<div class="container">
<div class="jumbotron">
<h1><?php echo $id?></h1>
<p>This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
<p><a class="btn btn-primary btn-lg">Learn more</a></p>
</div>
</div>
我想在此部分中显示变量。我没有正确创建阵列..
答案 0 :(得分:0)
您尝试传递数组,这意味着您可以使用foreach
。
首先,使用查询模型而不是控制器。在模型下移动代码,并在函数末尾添加此行:
return $viewdata;
创建一个控制器并在其中包含您的模型。然后创建另一个函数并定义模型的返回。 E.g:
$this->load->model('Your_model_class_name');
$data['viewdata'] = $this->Model_class_name->function_name();
$this->load->view('yourview', $data);
最后,您的观点。像这样编辑:
<div class="container">
<?php foreach($viewdata as $row) { ?>
<div class="jumbotron">
<h1><?php echo $row['id']; ?></h1>
<p>This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
<p><a class="btn btn-primary btn-lg">Learn more</a></p>
</div>
<?php } ?>
</div>