Codeigniter data transfer controller-> library-> view

I have a problem with the code. I am trying to send data from a controller, to a library, to a view.

I get this error in view:

Message: Undefined variable: crimes

File_name: views / crime_view.php

Line: 45

during debugging, I unload the $ data variable and get:

enter image description here

which shows that my variables exist.

in the library, im getting controller data using:

$data[] = $componentData; 

which will not work in this case. but if I'm in the library:

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

then it will work. for some reason, it does not process incoming arrays from the controller.

how can i make this 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: enter image description here

Q: How can I fix this to pass the necessary variables to it? so can i usually use the $ wait variable in the view?

+3
1

.

, - $data[] = ... $data = ...

, :

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

, ...

0

Source: https://habr.com/ru/post/1672324/


All Articles