Doug Molineux
Doug Molineux

Reputation: 12431

CodeIgniter Controller not Loading view with Parameters

Real basic CI question here, which I cant find anything on in the documentation. I think I may need some further configuration?? I have a function which loads a view and it works correctly, but when I send it parameters its doesn't load the view, any ideas??

Heres code with params (view does not load)

function grid($height,$width)
{
    echo $height."x".$width;

 $this->load->view("grid");

}

and here's without (view does load)

function grid()
{
    //echo $height."x".$width;

 $this->load->view("grid");

}

So Height and width is the only thing that echos in the first example, in the second the view is loaded. Thanks ahead of time!

Upvotes: 1

Views: 2725

Answers (1)

Justin Ethier
Justin Ethier

Reputation: 134275

You are supposed to have your controller pass parameters to the view as an array:

function grid($height,$width)
{
  $data = array();
  $data['height'] = $height;
  $data['width'] = $width;

  $this->load->view("grid", $data);
}

Then your view can render them:

echo $height."x".$width;

This allows for a clean separation of concerns between the Controller and View objects.

For more information see the section Adding Dynamic Data to the View in the CI User Guide.

Upvotes: 2

Related Questions