yii\helpers\BaseInflector::camel2words PHP Method

camel2words() public static method

For example, 'PostTag' will be converted to 'Post Tag'.
public static camel2words ( string $name, boolean $ucwords = true ) : string
$name string the string to be converted
$ucwords boolean whether to capitalize the first letter in each word
return string the resulting words
    public static function camel2words($name, $ucwords = true)
    {
        $label = trim(strtolower(str_replace(['-', '_', '.'], ' ', preg_replace('/(?<![A-Z])[A-Z]/', ' \\0', $name))));
        return $ucwords ? ucwords($label) : $label;
    }

Usage Example

 /**
  * @param WidgetsCrud $nextModel
  * @return string
  */
 public function generateWidgetActiveField($nextModel)
 {
     $controllerName = explode(' ', BaseInflector::camel2words(str_replace('Controller', '', StringHelper::basename($this->controllerClass))));
     $controller = '';
     $module = $this->moduleID ? "/{$this->moduleID}" : '';
     foreach ($controllerName as $item) {
         $controller .= (strlen($controller) ? '-' : '') . strtolower($item);
     }
     $nextModel->pathName = $nextModel->pathName ?: '_widgets';
     return str_replace(['{controller}', '{module}'], [$controller, $module], $this->render("views/{$nextModel->pathName}/_{$nextModel->widgetType}Input.php"));
 }