Craft 3 Class Reference

Class craft\services\Routes

Inheritance
craft\services\Routes » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/services/Routes.php

Routes service.

An instance of the Routes service is globally accessible in Craft via Craft::$app->routes.

Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
deleteRouteById() Deletes a route by its ID. craft\services\Routes
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getConfigFileRoutes() Returns the routes defined in config/routes.php craft\services\Routes
getDbRoutes() Returns the routes defined in the CP. craft\services\Routes
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
saveRoute() Saves a new or existing route. craft\services\Routes
trigger() Triggers an event. yii\base\Component
updateRouteOrder() Updates the route order. craft\services\Routes
Events
Event Type Description Defined By
EVENT_AFTER_DELETE_ROUTE craft\events\RouteEvent The event that is triggered after a route is deleted. craft\services\Routes
EVENT_AFTER_SAVE_ROUTE craft\events\RouteEvent The event that is triggered after a route is saved. craft\services\Routes
EVENT_BEFORE_DELETE_ROUTE craft\events\RouteEvent The event that is triggered before a route is deleted. craft\services\Routes
EVENT_BEFORE_SAVE_ROUTE craft\events\RouteEvent The event that is triggered before a route is saved. craft\services\Routes

Method Details

deleteRouteById() public method #

Deletes a route by its ID.

public boolean deleteRouteById ( \craft\services\int $routeId )
$routeId integer

getConfigFileRoutes() public method #

Returns the routes defined in config/routes.php

public array getConfigFileRoutes ( )

getDbRoutes() public method #

Returns the routes defined in the CP.

public array getDbRoutes ( )

saveRoute() public method #

Saves a new or existing route.

public craft\records\Route saveRoute ( array $uriParts, \craft\services\string $template, \craft\services\int $siteId null, \craft\services\int $routeId null )
$uriParts array The URI as defined by the user. This is an array where each element is either a string or an array containing the name of a subpattern and the subpattern
$template string The template to route matching requests to
$siteId integer, null The site ID the route should be limited to, if any
$routeId integer, null The route ID, if editing an existing route
throws craft\errors\RouteNotFoundException if|null $routeId is invalid

updateRouteOrder() public method #

Updates the route order.

public void updateRouteOrder ( array $routeIds )
$routeIds array An array of each of the route IDs, in their new order.

Event Details

EVENT_AFTER_DELETE_ROUTE event of type craft\events\RouteEvent #

The event that is triggered after a route is deleted.

EVENT_AFTER_SAVE_ROUTE event of type craft\events\RouteEvent #

The event that is triggered after a route is saved.

EVENT_BEFORE_DELETE_ROUTE event of type craft\events\RouteEvent #

The event that is triggered before a route is deleted.

EVENT_BEFORE_SAVE_ROUTE event of type craft\events\RouteEvent #

The event that is triggered before a route is saved.