Class yii\gii\Module

Inheritanceyii\gii\Module » yii\base\Module » yii\di\ServiceLocator » yii\base\Component » yii\base\BaseObject
Implementsyii\base\BootstrapInterface, yii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2-gii/blob/master/Module.php

This is the main module class for the Gii module.

To use Gii, include it as a module in the application configuration like the following:

return [
    'bootstrap' => ['gii'],
    'modules' => [
        'gii' => ['class' => 'yii\gii\Module'],
    ],
]

Because Gii generates new code files on the server, you should only use it on your own development machine. To prevent other people from using this module, by default, Gii can only be accessed by localhost. You may configure its $allowedIPs property if you want to make it accessible on other machines.

With the above configuration, you will be able to access GiiModule in your browser using the URL http://localhost/path/to/index.php?r=gii

If your application enables pretty URLs, you can then access Gii via URL: http://localhost/path/to/index.php/gii

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$allowedIPs array The list of IPs that are allowed to access this module. yii\gii\Module
$controllerMap array Mapping from controller ID to controller configurations. yii\base\Module
$controllerNamespace {@inheritdoc} yii\gii\Module
$defaultRoute string The default route of this module. yii\base\Module
$generators array|yii\gii\Generator[] A list of generator configurations or instances. yii\gii\Module
$id string An ID that uniquely identifies this module among other modules which have the same parent. yii\base\Module
$layout string|boolean The layout that should be applied for views within this module. yii\base\Module
$module yii\base\Module The parent module of this module. yii\base\Module
$newDirMode integer The permission to be set for newly generated directories. yii\gii\Module
$newFileMode integer The permission to be set for newly generated code files. yii\gii\Module
$params array Custom module parameters (name => value). yii\base\Module

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\Module
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
afterAction() This method is invoked right after an action within this module is executed. yii\base\Module
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
beforeAction() {@inheritdoc} yii\gii\Module
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
bootstrap() {@inheritdoc} yii\gii\Module
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
className() Returns the fully qualified name of this class. yii\base\BaseObject
clear() Removes the component from the locator. yii\di\ServiceLocator
createController() Creates a controller instance based on the given route. yii\base\Module
createControllerByID() Creates a controller based on the given controller ID. yii\base\Module
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
get() {@inheritdoc} yii\base\Module
getBasePath() Returns the root directory of the module. yii\base\Module
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getComponents() Returns the list of the component definitions or the loaded component instances. yii\di\ServiceLocator
getControllerPath() Returns the directory that contains the controller classes according to $controllerNamespace. yii\base\Module
getInstance() Returns the currently requested instance of this module class. yii\base\Module
getLayoutPath() Returns the directory that contains layout view files for this module. yii\base\Module
getModule() Retrieves the child module of the specified ID. yii\base\Module
getModules() Returns the sub-modules in this module. yii\base\Module
getUniqueId() Returns an ID that uniquely identifies this module among all modules within the current application. yii\base\Module
getVersion() Returns current module version. yii\base\Module
getViewPath() Returns the directory that contains the view files for this module. yii\base\Module
has() {@inheritdoc} yii\base\Module
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\Component
hasModule() Checks whether the child module of the specified ID exists. yii\base\Module
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() Initializes the module. yii\base\Module
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
runAction() Runs a controller action specified by a route. yii\base\Module
set() Registers a component definition with this locator. yii\di\ServiceLocator
setAliases() Defines path aliases. yii\base\Module
setBasePath() Sets the root directory of the module. yii\base\Module
setComponents() Registers a set of component definitions in this locator. yii\di\ServiceLocator
setInstance() Sets the currently requested instance of this module class. yii\base\Module
setLayoutPath() Sets the directory that contains the layout files. yii\base\Module
setModule() Adds a sub-module to this module. yii\base\Module
setModules() Registers sub-modules in the current module. yii\base\Module
setVersion() Sets current module version. yii\base\Module
setViewPath() Sets the directory that contains the view files. yii\base\Module
trigger() Triggers an event. yii\base\Component

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
checkAccess() yii\gii\Module
coreGenerators() Returns the list of the core code generator configurations. yii\gii\Module
defaultVersion() {@inheritdoc} yii\gii\Module
resetGlobalSettings() Resets potentially incompatible global settings done in app config. yii\gii\Module

Events

Hide inherited events

EventTypeDescriptionDefined By
EVENT_AFTER_ACTION yii\base\ActionEvent An event raised after executing a controller action. yii\base\Module
EVENT_BEFORE_ACTION yii\base\ActionEvent An event raised before executing a controller action. yii\base\Module

Property Details

$allowedIPs public property

The list of IPs that are allowed to access this module. Each array element represents a single IP filter which can be either an IP address or an address with wildcard (e.g. 192.168.0.*) to represent a network segment. The default value is ['127.0.0.1', '::1'], which means the module can only be accessed by localhost.

public array $allowedIPs = ['127.0.0.1''::1']
$controllerNamespace public property
public $controllerNamespace 'yii\gii\controllers'
$generators public property

A list of generator configurations or instances. The array keys are the generator IDs (e.g. "crud"), and the array elements are the corresponding generator configurations or the instances.

After the module is initialized, this property will become an array of generator instances which are created based on the configurations previously taken by this property.

Newly assigned generators will be merged with the core ones, and the former takes precedence in case when they have the same generator ID.

$newDirMode public property

The permission to be set for newly generated directories. This value will be used by PHP chmod function. Defaults to 0777, meaning the directory can be read, written and executed by all users.

public integer $newDirMode 511
$newFileMode public property

The permission to be set for newly generated code files. This value will be used by PHP chmod function. Defaults to 0666, meaning the file is read-writable by all users.

public integer $newFileMode 438

Method Details

beforeAction() public method

{@inheritdoc}

public void beforeAction ( $action )
$action
bootstrap() public method

{@inheritdoc}

public void bootstrap ( $app )
$app
checkAccess() protected method

protected integer checkAccess ( )
return integer

Whether the module can be accessed by the current user

coreGenerators() protected method

Returns the list of the core code generator configurations.

protected array coreGenerators ( )
return array

The list of the core code generator configurations.

defaultVersion() protected method (available since version 2.0.6)

{@inheritdoc}

protected void defaultVersion ( )
resetGlobalSettings() protected method

Resets potentially incompatible global settings done in app config.

protected void resetGlobalSettings ( )