getUniqueId() public method

Note that if the module is an application, an empty string will be returned.
public getUniqueId ( ) : string
return string the unique ID of the module.
Example #1
0
 /**
  * Returns available commands of a specified module.
  * @param \yii\base\Module $module the module instance
  * @return array the available command names
  */
 protected function getModuleCommands($module)
 {
     $prefix = $module instanceof Application ? '' : $module->getUniqueId() . '/';
     $commands = [];
     foreach (array_keys($module->controllerMap) as $id) {
         $commands[] = $prefix . $id;
     }
     foreach ($module->getModules() as $id => $child) {
         if (($child = $module->getModule($id)) === null) {
             continue;
         }
         foreach ($this->getModuleCommands($child) as $command) {
             $commands[] = $command;
         }
     }
     $controllerPath = $module->getControllerPath();
     if (is_dir($controllerPath)) {
         $files = scandir($controllerPath);
         foreach ($files as $file) {
             if (!empty($file) && substr_compare($file, 'Controller.php', -14, 14) === 0) {
                 $controllerClass = $module->controllerNamespace . '\\' . substr(basename($file), 0, -4);
                 if ($this->validateControllerClass($controllerClass)) {
                     $commands[] = $prefix . Inflector::camel2id(substr(basename($file), 0, -14));
                 }
             }
         }
     }
     return $commands;
 }
Example #2
0
 /**
  * @return string the controller ID that is prefixed with the module ID (if any).
  */
 public function getUniqueId()
 {
     return $this->module instanceof Application ? $this->id : $this->module->getUniqueId() . '/' . $this->id;
 }