-
Notifications
You must be signed in to change notification settings - Fork 0
Control Panel
Just like with Extension and Module routing, you have to extend your ExpressionEngine Addon file to use the corresponding EE Objects Controller Base route. In this case, that'll be EeObjects\Controllers\Cp.
You'll also have to add a new property to your Control Panel object called $route_namespace which is the namespace for route objects.
Note the below example uses the
setRouteNamespacemethod to set the$route_namespaceproperty.
use EeObjects\Controllers\Cp;
class Ee_objects_mcp extends Cp
{
protected $module_name = 'ee_objects';
public function __construct()
{
$this->setRouteNamespace('EeObjects\Addon\Controllers');
}
public function index()
{
return $this->route('index', func_get_args());
}
}Note that $route_namespace isn't directly one to one. EE Objects Controller does some magic to keep things compartmentalized. Using the below example, the namespace used to locate your Route objects would be Namespace\For\Your\Controllers\Cp\Routes.
Unlike any other Controller Route, Control Panel routes require an addition to your ExpressionEngine Control Panel object. The idea is you tell ExpressionEngine to your object then the Router takes over. For example, in the above example, we define an index method and then route it internally.
The route object itself would look like the below:
namespace EeObjects\Addon\Controllers\Cp\Routes;
use EeObjects\Addon\Controllers\Cp\AbstractRoute;
class Index extends AbstractRoute
{
protected $route_path = 'index';
public function process($id = false): AbstractRoute
{
return $this;
}
}