codeigniter data passing controller->library->view

不想你离开。 提交于 2020-01-03 19:04:43

问题


I have a codeigniter problem. Im trying to send data from a controller , to a library , to a view.

i get this error in the view:

Message: Undefined variable: crimes

FileName: views/crime_view.php

Line: 45

while debugging , i dump the $data variable, and get:

that shows that my variables exist.

in the library , im getting the controller data by using:

$data[] = $componentData; 

that would not work in this case. but if i in the library do:

$data['crimes'] = "test";

then it will work. for some reason it wont process the incomming arrays from the controller.

how can i get this to work?

full code:

    function renderComponent($componentData = array())   
    {
        $data[] = $componentData; // stores controller variables.
        $data['rankDetails'] = $this->CI->user->rank_for_xp($userId);

        var_dump($data);

        $this->CI->load->view('components/crime/views/crime_view', $data);
    }

example from the controller:

Q: How can i fix this to get it passing the variables needed? so i acually can get to use the $wait variable in the view?


回答1:


You have a two dimensional array.

I think somewhere $data[] = ... must be $data = ...

to debug your arrays you could do like this:

echo '<pre>';
print_r($data);
echo '</pre>';

This shows clearly that your array is in another array...



来源:https://stackoverflow.com/questions/32554394/codeigniter-data-passing-controller-library-view

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