Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Auth - Controller Best Practice
  • When the user is logged in, I need the details for the facility and the user/profile available in the template. So here is what I have done in the before() of my Template_Controller.... Is this best practice or should I be doing this a different way? To me it seems a little hacky so please any suggestions...
    //------------------------------------------------------------------------------
    // check to make sure the user is logged in
       
    if (\Auth::check())
    {
          // let's get the facility information
          $this->facility = Facility\Model_Facility::find(1); 
          $this->template->set_global('facility', $this->facility);
      
          // get the user's information
          $user = \Auth::instance()->get_user_id();
      
          $this->user = User\Model_User::find($user[1]); 
          $this->template->set_global('user', $this->user);
    }
    else
    {
          \Response::redirect(\Config::get('common.auth.login_url'));
    }
       
    //------------------------------------------------------------------------------
    // check to make sure the user has access
     
    if(!\Auth::has_access(array($this->request->module, array($this->request->controller.'/'.$this->request->action))))
    {
          // Set a HTTP 503 output header
         $this->response->status = 503;
        \Response::redirect(\Config::get('common.forbidden'));
    }
    
  • See https://github.com/abdelm/stationwagon/ In this example the Controller_Termplate is extended with Controller_Common. This way it's not "hacky"...
  • Thank you for the reply!! Sorry I should have mentioned, that is how mine is also... I used the stationwagon examples as a starting point... I extend Controller_Templates_Common (the code above) in my controllers.... The part I was really concerned with was is this the best way to get the practice and user vars loaded into my views? I need the information available in all of them and figured this was a better way than doing individual calls in all of my files...

Howdy, Stranger!

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

In this Discussion