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 string The namespace that controller classes are in. 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\BaseObject
__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 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
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() This method is invoked right before an action within this module is executed. yii\gii\Module
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
bootstrap() Bootstrap method to be called during application bootstrap stage. yii\gii\Module
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
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\BaseObject
hasModule() Checks whether the child module of the specified ID exists. yii\base\Module
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
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() Returns default module version. 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

The namespace that controller classes are in. This namespace will be used to load controller classes by prepending it to the controller class name.

If not set, it will use the controllers sub-namespace under the namespace of this module. For example, if the namespace of this module is foo\bar, then the default controller namespace would be foo\bar\controllers.

See also the guide section on autoloading to learn more about defining namespaces and how classes are loaded.

public string $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

This method is invoked right before an action within this module is executed.

The method will trigger the EVENT_BEFORE_ACTION event. The return value of the method will determine whether the action should continue to run.

In case the action should not run, the request should be handled inside of the beforeAction code by either providing the necessary output or redirecting the request. Otherwise the response will be empty.

If you override this method, your code should look like the following:

public function beforeAction($action)
{
    if (!parent::beforeAction($action)) {
        return false;
    }

    // your custom code here

    return true; // or false to not run the action
}
public boolean beforeAction ( $action )
$action yii\base\Action

The action to be executed.

return boolean

Whether the action should continue to be executed.

bootstrap() public method

Bootstrap method to be called during application bootstrap stage.

public void bootstrap ( $app )
$app yii\base\Application

The application currently running

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)

Returns default module version.

Child class may override this method to provide more specific version detection.

protected string defaultVersion ( )
return string

The version of this module.

resetGlobalSettings() protected method

Resets potentially incompatible global settings done in app config.

protected void resetGlobalSettings ( )