消息:使用数据数组的未定义变量 [英] MESSAGE: Undefined Variable using data array

查看:91
本文介绍了消息:使用数据数组的未定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据数组从数据库传输数据,它显示以下错误消息...

I'm using data array to transfer data from a database and it shows an error message given below...


PHP错误发生的严重性:通知消息:未定义的变量:
VOYAGE_INFO文件名:CLIENT / MANIFEST.PHP
文件:C:\XAMPP\HTDOCS\PHIVIDEC\APPLICATION\VIEWS\PORT\ \CLIENT\MANIFEST.PHP
线:40功能:_ERROR_HANDLER –

A PHP ERROR WAS ENCOUNTERED SEVERITY: NOTICE MESSAGE:UNDEFINED VARIABLE: VOYAGE_INFO FILENAME: CLIENT/MANIFEST.PHP FILE:C:\XAMPP\HTDOCS\PHIVIDEC\APPLICATION\VIEWS\PORT\CLIENT\MANIFEST.PHP LINE:40 FUNCTION:_ERROR_HANDLER –

这是我的代码:

public function manifest() {
    $this->Auth->authCheck();
    $data = $this->template();

    $data_array = array(
        'voyage_info' =>$this->PortManifestModel->get_voyage()->result(),
    );

    // your code here

    $this->load->view("port/client/manifest", $data, $data_array);
}

在我的查看页面中:

<a class="btn btn-primary primary-bg btn-lg  col-md-4 m-2 btn-cus" href="">
    <?php foreach($voyage_info as $voyage) {  ?>
        <h3>Voyage <?=$voyage->voyage_number?></h3> 
        <small>Schedule</small>
    <?php }  ?>
</a>

我需要做些什么来解决这个问题?

What do I need to do to solve this?

推荐答案

必须通过视图加载方法的 second参数中的数组或对象将数据从控制器传递到视图。因此,当控制器加载视图时,它会在第二个参数中找到数据。

Data has to be passed from the controller to the view by way of an array or an object in the second parameter of the view loading method. So when controller loads view it find data in the second parameter.

而在第二个 $ data 中,您没有提供数据,而不是您尝试向其传递第三个参数

Whereas in second $data you didn't provide data, rather you are trying to pass it the third parameter

请按以下所示更新代码...

Please update your code as given below...

来自

$this->load->view("port/client/manifest", $data, $data_array);

$this->load->view("port/client/manifest", $data_array);

关于视图的第三个参数,请查看官方
的详细信息来源在下面给出...

Regarding the third parameter of view please check details from official Source given below...


第三个可选参数可让您更改
方法的行为,以便它以字符串形式返回数据,而不是将
发送给您浏览器。如果您想以某种方式处理
中的数据,这将很有用。如果将参数设置为TRUE(布尔值),它将返回
数据。默认行为是false,它将其发送到您的浏览器。
如果要返回数据,请记住将其分配给变量:

There is a third optional parameter lets you change the behavior of the method so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to TRUE (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:

这篇关于消息:使用数据数组的未定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆