Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Output filtering problem
  • Hi, I've got custom controller:
    class Controller_Base extends Controller_Template
    {
     protected $images_path = '';
     protected $images_store = '';
     
     public function before()
     {
      parent::before();
      
      $this->current_user = Auth::check() ? Model_User::find_by_username(Auth::get_screen_name()) : null;
      $this->images_path = Auth::check() ? Uri::base(false).'upload'.DS.$this->current_user->username.DS : null;
      $this->images_store = Auth::check() ? DOCROOT.'upload'.DS.$this->current_user->username.DS : null;
    
      View::set_global('current_user', $this->current_user);
      View::set_global('images_path', $this->images_path);
     }
    
    }
    

    And my welcome controller:
    class Controller_Welcome extends Controller_Base
    {
     public function action_profile()
     {
           $user = Model_User::find($this->current_user->id);
           $this->template->set_global('user', $user, false);
           $this->template->content = View::forge('welcome/profile');
     }
    }
    

    But output is escaped. What am I doing wrong? How can I set output not to be escaped?
  • Which output is escaped where?
  • As you can see there is a line
    $this->template->set_global('user', $user, false);
    

    this output (user variable) is loaded into text boxes and text areas fields on the view.
  • Why do you use set_global() here? Do you have multiple views, or nested views loaded that need to access the $user variable? I've looked in the code of the view class, and I can't see any reason why this would be escaped. You're not confused with 'current_user' which is assigned this same user object in your base controller, but then with the auto filter set (which means it is escaped)? Any reason why you're querying the same record twice? And pass it twice? And what happens if $this->current_user is NULL (which is the case when authentication fails)? In that case $this->current_user->id will generate a PHP error...
  • You are right set_global() is not required here. Unfortunatelly I'm sure I'm using $user variable in my view.
    Last thing you mentioned is also true but I've deleted all irrelevant lines of code. So the lines is onlu the part or my real code. I've changed lines in Controller_Base to:
    View::set_global('current_user', $this->current_user, false);
    View::set_global('images_path', $this->images_path, false);
    

    and used $current_user in my view. Everything seems to work. Still no idea what is the problem with setting global variable in derived controller.

Howdy, Stranger!

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

In this Discussion