-
Book Overview & Buying
-
Table Of Contents
concrete5 Cookbook
A unique and advanced feature of the package controller is the ability to run code automatically whenever a page is accessed. This can give add-on developers tremendous potential to tap into system events, hook into site HTTP requests, and more. In this recipe, we will show how easy it is to automatically run code from our package whenever a page is visited by redirecting all requests containing a special parameter to the home page.
We will use the simple add-on package that was created in the previous recipe for this example. The code for this recipe and all others is available for download on the book's website.
The steps for using the package controller to execute custom code are as follows:
Open the package controller file, located at /packages/basic_addon/controller.php.
Add a function called on_start that will redirect anyone that enters the parameter redirect_me in the URL.
public function on_start() {
if ...
Change the font size
Change margin width
Change background colour