CodeIgniter Forums

Full Version: basic stuff, include a view in a main php file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]alebenson[/eluser]
hi there!...
yes i know this is basic stuff but i cant figure

i have the main page.php (that is not created by CI)...
but i want to add a feature, like a sidebar.
i have a sidebar_left_view and the controller
but i dont know how to mix that with the page.php

i try with
Code:
<?php include (site_url("sidebar/left"));?>

but doesnt work...

any ideas?
thanks

El Forum

[eluser]wiredesignz[/eluser]
Two things, your are using a full URL to the file which probably won't work, and include needs filename.extension

El Forum

[eluser]alebenson[/eluser]
Well i was reading the User Guide about Views and gives an example of multiples views

Code:
class Page extends Controller {
   function index()
   {
      $data['page_title'] = 'Your title';
      $this->load->view('header');
      $this->load->view('menu');
      $this->load->view('content', $data);
      $this->load->view('footer');
   }
}

what can i do, if the 'menu' need some vars to be passed ?
ok, i guess like 'content' adding $data, but the $data for the menu, is on the Menu Controller, and not in the Page controller

thanks!

El Forum

[eluser]xwero[/eluser]
I like to use variables that reflect the name of the view file for easy troubleshooting
Code:
class Page extends Controller {
   function index()
   {
      
      $this->load->view('header');
      $menu['links'] = $this->model->urls();
      $this->load->view('menu',$menu);
      $content['page_title'] = 'Your title';
      $this->load->view('content', $content);
      $this->load->view('footer');
   }
}

El Forum

[eluser]alebenson[/eluser]
THANKS xwero!!! i did it!