0

It appears that in Zend Framework 2, every controller seems to extend the AbstractActionController by default.

I was thinking if there's a way for all my controllers to extend a CustomController that in turn extends the AbstractActionController.

The purpose of this CustomController, is to do checks like whether a user is authorized to access my other controllers or not and also may be generate menu navigation.

Is this still a good idea and if so, will doing this work?

**IndexController.php**

class IndexController extends CustomController {

}

**CustomController.php** 

class CustomController extends AbstractActionController {

}

Thanks,

1 Answer 1

1

Of course you can extend a base class and it will work.

Is it a good idea ? It really depends on your project. For authentication and permission check, you could also use a module like ZfcRbac or BjyAuthorize

For navigation, there is spiffy-navigation

If you use php 5.4+, Traits can also be an alternative to inheritance

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.