Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Base Controller
  • What is the best way to call a base controller?
    I noticed that while it worked fine before, the __construct method throws an error with the new RC1. "ErrorException [ Error ]: Call to a member function body() on a non-object COREPATH/classes/controller/template.php @ line 55"
    the Before method throws a different type of error : "Warning! ErrorException [ Warning ]: Attempt to assign property of non-object" pointing to the template call $this->template->title = 'Search Page'; Thank you for your help
  • We're going to need a bit more details here. But probably this is because you're extending the template controller and overwriting the __construct() method? You need to copy-paste the exact method signature (params and all) to your own extension and pass them to parent::__construct(), otherwise things will go wrong.
  • Hi there,
    thanks for the quick reply.
    here is what I am trying to do ( FYI, I am not able to highlight code) class Controller_Search extends Controller_Template { public function __construct() parent::__construct(); new Base(); }
    public function action_query ($type)
    $data = Model_Search::$type(); $this->template->title = 'Search Page'; $this->template->content = View::factory('search',$data); }
    } but this gives me an error : ErrorException [ 4096 ]: Argument 1 passed to Fuel\Core\Controller::__construct() must be an instance of Fuel\Core\Request, none given, called in /Users/testsite/Fuel/fuel/app/classes/controller/search.php on line 9 and defined. while on the subject , I am not sure I understand the difference between the "before" method and the "__construct" method. any help there is greatly appreciated thanks again for your help
  • I had the same issue.. have a look at this for answer http://fuelphp.com/forums/topics/view/808
  • Thank you. That surely helped. do you know however the difference between : The before method and the constructor method? why would I use one versus the other? what are the $request & $response parameters we need to pass? I appreciate the help
  • The before() method is always called before any controller method is called, as such it is a replacement for using the constructor. The constructor itself is in use by Fuel to assign the internal connections from the request to the controller and from the conntroller to the response. (a request is made, a controller is run, and a response is given) You can of course still replace the __construct() method as long as you pass the required params to the parent::__construct(). Edit: most of this is explained in the docs btw.
  • Thank you Jelmer for a thorough explanation.
    I also wanted to say that I did my best looking in docs but could not find anything. Perhaps a search function in docs would help :)
    thanks again

Howdy, Stranger!

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

In this Discussion