Welcome Guest, Not a member yet? Register   Sign In
basic stuff, include a view in a main php file
#1

[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
#2

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

[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!
#4

[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');
   }
}
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB