问题
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