Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Opinion regarding views
  • Hello Guys, I'm new to fuel as many people and need an opinion from somebody, here's the scenario. I have a base class and this base class contains a private method called load_view(), where it's inherited controller classes can pass a view and generate the whole page. Method load_view()
            function _load_view($view)
     {
      //header part
      $header = View::factory('common/header', 
       array('member_id'=>$this->member_id, 'member_name'=>$this->member_name, 'division_name'=>$this->division_name)
      );
      
      //template - main
      $template = View::factory('template', 
       array('content'=>$view)
      );
      $template->header = $header;
      
      $this->response->body = $template;
     }
    

    template.php
    echo $header;
    echo $content;
    echo View::factory('common/footer');
    

    So the main problem I have is making variables accessible through out the entire template, for example variable that get passed in to the header should be available in 'common/footer' as well. since I'm coming from Codeigniter I'll show what I mean. template.php
    $this->load->view('header);
    $this->load->view('content');
    

    Usage
    $this->load->view('template', array( 'var' => 'foo' )); //$var is available in both header and content.
    
    Any idea?
  • View docs, look for the View::set_global() method.
  • Jelmer Schreuder wrote on Friday 6th of May 2011:
    View docs, look for the View::set_global() method.
    Thank you so much. :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion