MESSAGE: Undefined Variable using data array [duplicate]

孤街浪徒 提交于 2020-01-07 08:35:13

问题


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

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 –

Here's my code:

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);
}

In my view page:

<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?


回答1:


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.

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...

From

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

To

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

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

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:



来源:https://stackoverflow.com/questions/51890662/message-undefined-variable-using-data-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!