Welcome Guest, Not a member yet? Register   Sign In
IDEA: Controller Extended by Default
#7

Let's call it BaseController. That way for people auto-routing it shouldn't conflict with anything they want to build. Don't add the constructor, though. That's for each controller to use on their own. Instead, override the initController method:

Code:
class Base extends Controller
{
   protected $helpers = [];

   public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
   {
        parent::initController();

       // Autoload any models, libraries, etc, here.
   }
}

Adding that to the system routes is a good idea, also.

Finally - please add a comment in the class docblock what it's intended usage is, a small example maybe, and a warning that all methods should be protected or private for security reasons.

And updated docs, of course.

Then I'm ok with that being added.
Reply


Messages In This Thread
IDEA: Controller Extended by Default - by MGatner - 03-18-2019, 07:28 AM
RE: IDEA: Controller Extended by Default - by kilishan - 03-19-2019, 08:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB