Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Error 2048 - Declaration of before() should be compatible with that of Controller_Template::before()
  • What does error 2048 - Declaration of Controller_Admin::before() should be compatible with that of Fuel\Core\Controller_Template::before() - mean? If I read the docs correctly, I need to include parent::before(); in my own controllers before() My code looks like this and logs error 2048.
    class Controller_Admin extends Controller_Template {
        
        public $template = 'template_admin';
        
    //--------------------------------------------------------------------------------------------------------
    
        public function before() {
            
            // Make sure the template system works
            parent::before();
            
            // Load package auth
            Fuel::add_package('auth');
            
            // Check for valid login
            if ( ! Auth::check() and Uri::string() != 'admin/login')
            {
               Response::redirect('/admin/login', 'refresh');   
            }
        }
    ...
    

    My question is: 'How can I make my Controller_Admin::before() compatible with that of Fuel\Core\Controller_Template::before()? --
    Thanks,
    Jeroen
  • Could probably just remove that data stuff. It fixed an issue that has since been fixed in other ways. Kill it whenever it makes sense.
  • but not adding the data stuff gives an error in the logs... And how we hate errorlogs...
  • Check the method definitions in Controller_Template (fuel/core/classes/controller/template.php). You'll see that before is defined as
    public function before($data = null)
    
  • Got it!
    Maybe you should update the docs and put there the correct solution?
    class Controller_Admin extends Controller_Template {
        
        public $template = 'template_admin';
        
    //--------------------------------------------------------------------------------------------------------
    
        [b]public function before($data = null) {[/b]
            
            // Make sure the template system works
            parent::before();
            ...
    
  • I've put a notice in the docs to check the parent definitions when overloading methods.
  • @WanWizard should it even be there? before() always gets called without params, thus allowing it to take params seems useless? Or am I mistaken?
  • Thanks, I had the same problem.
  • Harro Verton wrote on Sunday 7th of August 2011:
    I've put a notice in the docs to check the parent definitions when overloading methods.

    I don't mean this as bad criticism, but good Docs are the backbone of any framework.
    I haven't found your notice in the docs or I misread them. I think if you would update the notice in the template-doc with a little extra warning, nobody will have to ask this question again... I'm not a native English speaker, but I recommend something like:
    Please note: if you have a before() method in your template controller extension you must add parent::before(); to that method or the $this->template will not be available. Make sure your before method is compatible with that of the Controller_Template by changing your before() method into before($data = null).
  • Be patient, I haven't commited the change yet. I'm busy with things that pay my bills at the moment. As soon as I commit the change, it will become live on http://fuelphp.com/dev-docs.
  • Harro Verton wrote on Sunday 7th of August 2011:
    Be patient, I haven't commited the change yet. I'm busy with things that pay my bills at the moment. As soon as I commit the change, it will become live on http://fuelphp.com/dev-docs.

    Sorry, I misunderstood you ;) Like I said: /me no speak Englais good...
  • Harro Verton wrote on Sunday 7th of August 2011:
    I've put a notice in the docs to check the parent definitions when overloading methods.
    I don't know. All I know it that the parent defines it with a parameter. So either it has to go there, or it has to be used when you overload the method...

Howdy, Stranger!

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

In this Discussion