Template Library and Passing $data |
[eluser]Freewolf[/eluser]
Greetings All, I am fairly new to CI and the Template Library. http://williamsconcepts.com/ci/codeignit...index.html And I am having trouble figuring something out. I have a controller with a number of functions. And I am trying to avoid repeat writing of code. the section in the Locations main controller that has $data['tabs'] = which_tabs($locations); has information that will be needed on each page. However when I pass $data in the methods, the variables $tabs is not a valid variable. So basically what I need to know is if there is a why I can plug some information that is repetitive into the $data variable and pass to the methods. The which_tabs() functions makes a call to the DB. And I would prefer not to use that in each method. I am thinking that I should be able to make the call into main controller, load the info into the data variable, and then make that variable available to the methods. How can I go about doing this? class Locations extends Controller { function Locations() { parent::Controller(); $this->load->helper('locations'); $location = location(); $data['tabs'] = which_tabs($location); $this->template->write_view('header','template/header'); $this->template->write_view('footer','template/footer'); } function logan() { $this->template->write_view('content','locations/location',$data); $this->template->render(); } function ogden() { $this->template->write_view('content','locations/location',$data); $this->template->render(); }
[eluser]Cesar Kohl[/eluser]
Forget that. Instead try this: http://maestric.com/doc/php/codeigniter_template
[eluser]Eric Barnes[/eluser]
How about this: Code: class Locations extends Controller { |
Welcome Guest, Not a member yet? Register Sign In |