-
Notifications
You must be signed in to change notification settings - Fork 0
Home
The Controllers library allows ExpressionEngine developers to compartmentalize their Actions, Template Tags, Extensions, and Control Panel methods, into stand-alone objects instead of containing everything within a single file in a single class.
When you use EE Objects Controllers, you're no longer up against indecipherable scrolling and searching for what you want to work on. Now, everything's compartmentalized and centralized.
To start using the Controllers library, you have to make a couple changes to your ExpressionEngine Addon.
- ExpressionEngine >= 5.5
- PHP >= 7.1
Add ee-objects/controllers as a requirement to your composer.json:
$ composer require ee-objects/controllersEvery Controller object can be used by itself or alongside other Controller types.
Depending on which portion of your Addon you want to setup as Controllers, you have to make a make a change.
Note that every Controller requires the
route_namespaceproperty to let EeObjects know where your Routes are stored.
use EeObjects\Controllers\Extension;
class Your_addon_ext extends Extension
{
protected $route_namespace = 'Namespace\For\Your\Controllers';
}use EeObjects\Controllers\Cp;
class Your_addon_mcp extends Cp
{
protected $route_namespace = 'Namespace\For\Your\Controllers';
}use EeObjects\Controllers\Module;
class Your_addon extends Module
{
protected $route_namespace = 'Namespace\For\Your\Controllers';
}Regardless of the domain of your Controller, every Route requires a single object that follows a couple rules:
- Inherits from a base Route object
- Implements a
processmethod - It must be available at the namespace you set with the
route_namespaceproperty.
A very basic example would be:
namespace EeObjects\Addon\Controllers\Extension\Routes;
use EeObjects\Controllers\Extension\AbstractRoute;
class TemplatePostParse extends AbstractRoute
{
public function process(string $final_template, bool $is_partial, $site_id, array $currentTemplateInfo): string
{
return $final_template;
}
}