[英]When i'm transfering to another page getting data(s) (PHP Error Message:Trying to get property of non-object)
I want to transfer data in another controller and show it on another page but it shows "Message: Trying to get property of non-object" 我想在另一个控制器中传输数据并在另一页上显示它,但显示“消息:试图获取非对象的属性”
Here's my code 这是我的代码
manifest.php(viewpage) - Wherein i want to get the value of voyage_id manifest.php(viewpage)-其中我想获取voyage_id的值
<?php foreach($voyage_info as $voyage) { ?>
<input type="hidden" name="voyage_id" value="<?=$voyage->voyage_id?>">
<a class="btn btn-primary primary-bg btn-lg col-md-4 m-2 btn-cus" href="<?php echo base_url('PortClient/view_voyage/');?>">
<h3>Voyage - <?=$voyage->voyage_number?></h3>
<small>Schedule - <?=$voyage->expected_arrival?> </small>
</a>
<?
php } ?>
controller(getting the value of voyage_id) 控制器(获取voyage_id的值)
public function view_voyage() {
$this->Auth->authCheck();
$data = $this->template();
$voyage_id = $this->session->userdata('voyage_id');
$data['view_cargo'] = $this->PortManifestModel->view_voyage($voyage_id)->result_array();
// your code here
$this->load->view("port/client/sub_manifest/sub_manifest_1", $data);
}
View page(Wherein i want to show the data) 查看页面(我要在其中显示数据)
<div class=" col-md-2">
<label>Container Number: <?=$view_cargo->container_id?></label>
</div>
but it shows A PHP Error was encountered Severity: Notice 但它显示遇到PHP错误严重性:注意
Message: Trying to get property of non-object 消息:试图获取非对象的属性
Filename: sub_manifest/sub_manifest_1.php 档案名称:sub_manifest / sub_manifest_1.php
Line Number: 37 行号:37
Line 37 is Container Number: container_id?> 第37行是容器编号:container_id?>
what do i need to do? 我需要做什么?
1) You're using result_array() in your controller although you only want one result; 1)尽管只需要一个结果,但您在控制器中使用了result_array(); use row_array() instead.
使用row_array()代替。
2) $view_cargo is not an object, it's an array, so do: 2)$ view_cargo不是对象,它是一个数组,因此:
<label>Container Number: <?=$view_cargo['container_id']?></label>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.