tags:

views:

12

answers:

1

Hi Everyone!

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!

+1  A: 

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.

Justin Ethier
Ok well thank you for responding firstly. I realize that eventually I will be sending this to the view, but for some reason the view simply doesn't load when i change the uri to /grid/331/232 so i tried echoing it to see if it was just getting passed, it was just for debugging really. If I echo from a controller does that screw things up? Sorry, kinda new to CI
Pete Herbert Penito
Yes, technically it should work. But in CI the view is responsible for rendering the page, so any output from the controller is suspect. Have you checked your web server's error logs to see if you can track down why the page is not being rendered?
Justin Ethier
Good call thanks man, I loaded it in firebug and had a couple errors, In the view I include a script which was ../js/my.js right? so when a uri segment was added the paths changed and it couldn't find those files so it was halting the render altogether! bloody thing! Thanks ive spent ages on this
Pete Herbert Penito
No problem, glad you tracked it down :)
Justin Ethier