views:

40

answers:

3

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.

A: 

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;

sitesbyjoe
I am already adding $link to $data array, as in the code above. Though I tried your way, but still it does not work. Can there be any issue with whats the source of $server and $name? They are values that I receive from $this->input->post('server'); and $this->input->post('name'); Still not sure whats the bug.
Angad Singh
A: 

You definitely need to double check the incoming values of those post variables. Make sure your form is passing them correctly too.

sitesbyjoe
This should have been added as a comment underneath your original answer :).
DRL
A: 

the problem is somewhere else, the code is right. check if $server and $name are empty.

mg