CodeIgniter passing dynamic data from controller to view
I 开发者_如何学编程am passing an array to a view from a controller. Simple stuff. Should work, but is behaving rather too strangely and I cannot figure out the bug.
This is the controller-
$link = "http://" . $server . ".something.com/uploads/" . $name;
$data = array(
'name' =>$name,
'server'=>$server,
'link'=>$link,
'username'=>$username
);
$this->load->view('photo_edit', $data); //sending $data to view
This is the view -
<img src = "<?php echo $link; ?>"/>
When the view loads, the $link
is just this - http://.something.com/uploads/
But when I echo the $link in the controller, its totally fine (with both the $server
and $name
showing correctly). There is some issue with passing the $link
.
You need to add $link to your $data array so the view can see it.
Do this instead: $data['link'] = "http://" . $server . ".something.com/uploads/" . $name;
You definitely need to double check the incoming values of those post variables. Make sure your form is passing them correctly too.
the problem is somewhere else, the code is right.
check if $server
and $name
are empty.
精彩评论