dotkernel / dot-controller

DotKernel controller like middleware component
https://docs.dotkernel.org/dot-controller/
MIT License
2 stars 2 forks source link

Shouldn't indexAction() be mandatory in `AbstractController` class? #11

Closed gabidj closed 6 years ago

gabidj commented 7 years ago

In Dot\Controller\AbstractActionController::dispatch() the index action is the default action. If it doesn't exist next middleware will be called will generate a 404 error.

Dot\Controller\AbstractController::getMethodFromAction() will return indexAction for no action given.

Wouldn't it be better to add the indexAction() method ?

It helps the developer see his middleware was routed.

n3vrax commented 7 years ago

I get that when first using controllers and forgetting to define the indexAction, the 404 response might be a bit confusing, but a developer should be aware of what he's doing. We also recommend, in our documentation, to define this index action as a default one.

I'll say from start that the arguments to make this change or not are balanced. But I'm still slightly reserved regarding this change. Does it add real benefits?

Consider this

And let's not forget that Zend Expressive and DotKernel are for responsible developers that don't want to be restricted by so many rules as in the case of a full stack framework. The fewer, the better :)

To conclude, the strongest argument I can give for leaving things as they are is that developers, being able to define their routes at will, they should be able to define the controller actions accordingly. The indexAction is more of a convention. If you know your route supports paths with an optional action parameter, you should define the index action, otherwise you won't need it.

We'll might reconsider this for next versions, but for now we'll keep structural changes to minimum and focus on bug fixing instead

Thanks! Tibi