Angad Singh
Angad Singh

Reputation: 11

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.

Upvotes: 1

Views: 2991

Answers (3)

molli
molli

Reputation: 313

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

Upvotes: 0

sitesbyjoe
sitesbyjoe

Reputation: 1861

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

Upvotes: 0

sitesbyjoe
sitesbyjoe

Reputation: 1861

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;

Upvotes: 0

Related Questions