How do I add Requirements to an 'Controller' Extension


#1

Silverstripe Version:
4.2.2
Question:
How do I add Requirements to an ‘Controller’ Extension-Class

Hi, I try to extend the Page.php via an Extension. And I need to add some Javascript/Stylsheet-Files to the extended PageType.
Normally I d have to add the requirement-statement to the init-function of the controller, but overwriting does not work.

How will it work?

// Include any relevant code. If you have a lot of code, link to a gist instead.

#2

Hi Fabian,

The init() function will be in PageController rather than Page and you can’t override any existing methods if you’re using an extension, you would have to sub-class PageController instead to do that.

If you’re using an extension you can use the onBeforeInit or onAfterInit hook on Controller to fire some code before or after the init() method executes.

See: https://docs.silverstripe.org/en/4/developer_guides/extending/extensions/#modifying-existing-methods