Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Call to a member function body() on a non-object
  • Not sure what am doing wrong here..i trying to add construct() to load asset path.. but it doesn't like it. How else would i add the asset path to a extended base controller?
    <?php
    
    class Controller_Base_Admin extends \Controller_Template {
    
        public $template = 'templates/admin/template';
    
        function __construct() {
            \Asset::add_path('assets/themes/admin/');
        }
    
    }
    

    ErrorException [ Error ]: Call to a member function body() on a non-object COREPATH/classes/controller/template.php @ line 55 50 // After contorller method has run output the template
    51 public function after()
    52 {
    53 if ($this->auto_render === true)
    54 {
    55 $this->response->body($this->template);
    56 }
    57
    58 return parent::after();
    59 }
    60
  • Your constructor is defined without required parameters, and isn't calling the parent constructor
    <?php
    
    class Controller_Base_Admin extends \Controller_Template {
    
        public $template = 'templates/admin/template';
    
     public function __construct(\Request $request, \Response $response)
        {
            parent::__construct($request, $response);
    
            \Asset::add_path('assets/themes/admin/');
        }
    }
    
  • The same goes for before() and after() methods. You must call parent's methods to overwrite them.
    public function before() {
    
      parent::before();
    
    
      // Your code.
    
    }
    
    public function after() {
    
      parent::after();
    
    
      // Your code.
    
    }
    
  • thanks guys!

Howdy, Stranger!

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

In this Discussion