Naming convention

In order to allow auto-loading, Yii2 uses a simple standard to set names.

Routes that refer respectively to module, controller, and the action requested take the following format:


We will look at each element in detail as follows:

  • The ModuleID is optional, so often the format is ControllerID/ActionID
  • The ModuleID must be specified in the module's configuration property, under the same name
  • The ControllerID and ActionID should contain only English characters in lowercase, digits, underscores, dashes, and forward slashes

An example of route is http://hostname/index.php?r=site/index, where site is the ControllerID and index is the ActionID.

Starting from ControllerID, it is very easy to create the Controller ...

Get Yii2 By Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.