Deprecated: Swapping out the Base Controller

Important Note

We are keeping this documentation available for posterity but it is not really recommended to perform this: by overriding the base page controller in this way you risk running custom code on not only every front-end page, but also every Dashboard page – potentially slowing your site down and making it work in strange ways. Instead, it's recommended to simply create your own custom page controller that your single pages and page types extend from, and simply forking any core controllers (like controllers/single_page/page_not_found.php) and changing them to inherit from your custom page controller.

Note: this requires 5.7.4 or greater. It may not work in version 8.0 or greater.

Does some built of business logic in your site have to be available or run on every page? You might need to swap out the base page controller for your own custom page controller. This can be done by rebinding the "controller/page/default" pointer in the Concrete CMS class loader to point to your own custom page controller class.

public function on_start()
{
    Core::bind('\PageController', '\Your\Custom\PageController');
}

Now any time a base page is loaded that doesn't have a custom single page or page type controller, this controller will be used for it.

Setup the Alias

Then, set up an alias from \PageController to your custom page controller, by adding this file into application/config/app.php:

return array(
    'aliases' => array(
        'PageController' => '\Your\Custom\PageController'
    )
);

Extension Notes

Note: Any custom page type controller or single page controllers that you create will have to extend this controller, rather than \Concrete\Core\Page\Controller\PageController.