/** * @inheritdoc */ public function init() { parent::init(); if (!$this->header) { $this->header = "<h2>" . Inflector::camel2words($this->model->formName()) . " change log:</h2>"; } }
/** * @see \yii\grid\GridView::getColumnHeader($col) * @inheritdoc */ public function getColumnHeader($col) { if ($col->header !== null || $col->label === null && $col->attribute === null) { return trim($col->header) !== '' ? $col->header : $col->grid->emptyCell; } $provider = $this->dataProvider; if ($col->label === null) { if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQueryInterface) { /** * @var \yii\db\ActiveRecord $model */ $model = new $provider->query->modelClass(); $label = $model->getAttributeLabel($col->attribute); } else { $models = $provider->getModels(); if (($model = reset($models)) instanceof Model) { $label = $model->getAttributeLabel($col->attribute); } else { $label = Inflector::camel2words($col->attribute); } } } else { $label = $col->label; } return $label; }
/** * @inheritdoc */ public function renderHeaderCellContent() { if ($this->header !== null || $this->label === null && $this->attribute === null) { return parent::renderHeaderCellContent(); } $provider = $this->grid->dataProvider; if ($this->label === null) { if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQueryInterface) { /* @var $model Model */ $model = new $provider->query->modelClass(); $label = $model->getAttributeLabel($this->attribute); } else { $models = $provider->getModels(); if (($model = reset($models)) instanceof Model) { /* @var $model Model */ $label = $model->getAttributeLabel($this->attribute); } else { $label = Inflector::camel2words($this->attribute); } } } else { $label = $this->label; } return $label; }
function wp_get_nav_menu_object($menu) { $menu_obj = false; if (is_object($menu)) { $menu_obj = $menu; } if ($menu && !$menu_obj) { // if (strtolower($menu) == 'primary-menu' || strtolower($menu) == 'primary_menu') { $menu_obj = ['term_id' => $menu, 'name' => Inflector::camel2words($menu), 'slug' => $menu, 'term_group' => '0', 'term_taxonomy_id' => $menu, 'taxonomy' => 'nav_menu', 'description' => '', 'parent' => '0', 'count' => '1', 'filter' => 'raw']; $menu_obj = json_decode(json_encode($menu_obj, false)); $menu_obj = new WP_Term($menu_obj); // } // $menu_obj = get_term( $menu, 'nav_menu' ); // if ( ! $menu_obj ) { // $menu_obj = get_term_by( 'slug', $menu, 'nav_menu' ); // } // if ( ! $menu_obj ) { // $menu_obj = get_term_by( 'name', $menu, 'nav_menu' ); // } } if (!$menu_obj || is_wp_error($menu_obj)) { $menu_obj = false; } return apply_filters('wp_get_nav_menu_object', $menu_obj, $menu); }
/** * @inheritdoc */ public function init() { if ($this->attribute) { $field = str_replace(['[]', '][', '[', ']', ' ', '.'], ['', '-', '-', '', '-', '-'], $this->attribute); } else { $field = false; } if (empty($this->inputOptions['data-field']) && $field) { $this->inputOptions['data-field'] = $field; } if (empty($this->contentOptions['data-column']) && $field) { $this->contentOptions['data-column'] = $field; } if (empty($this->headerOptions['data-column']) && $field) { $this->headerOptions['data-column'] = $field; } if ($this->header === null) { if ($this->grid->model instanceof Model && !empty($this->attribute)) { $this->header = $this->grid->model->getAttributeLabel($this->attribute); } else { $this->header = Inflector::camel2words($this->attribute); } } if ($this->value === null) { $this->value = [$this, 'renderInputCell']; } elseif (is_string($this->value)) { $this->attribute = $this->value; $this->value = [$this, 'renderTextCell']; } }
/** * @inheritdoc */ public function afterFind() { parent::afterFind(); if (empty($this->description)) { $this->description = Inflector::camel2words($this->name, true); } }
public function actionIndex($file) { if (!preg_match('/^[a-zA-Z0-9-_]+$/', $file)) { throw new HttpException(400, 'Parameter validation failed'); } $html = file_get_contents(\Yii::getAlias($this->module->htmlUrl . "/{$file}.html")); return $this->render('index', ['html' => $html, 'headline' => Inflector::camel2words($file)]); }
public function generateAttributeLabel($name) { $label = Inflector::camel2words($name); // the following part is taken from Gii model generator if (!empty($label) && substr_compare($label, ' id', -3, 3, true) === 0) { $label = substr($label, 0, -3) . ' ID'; } return $label; }
public function __call($name, $params) { $redisCommand = strtoupper(Inflector::camel2words($name, false)); if (in_array($redisCommand, $this->redisCommands)) { return $this->executeCommand($name, $params); } else { return parent::__call($name, $params); } }
/** * @param Module $module * * @return array */ public function getControllers($module) { $files = FileHelper::findFiles($module->controllerPath, ['only' => ['*Controller.php']]); return ArrayHelper::getColumn($files, function ($file) use($module) { $class = pathinfo($file, PATHINFO_FILENAME); $route = Inflector::camel2id($class = substr($class, 0, strlen($class) - strlen('Controller'))); return new ControllerModel(['route' => $module->uniqueId . '/' . $route, 'label' => Inflector::camel2words($class)]); }); }
public function getElements() { $files = AppHelper::findDirectories(Yii::getAlias('@worstinme/zoo/elements')); $files = array_unique(array_merge($files, AppHelper::findDirectories(Yii::getAlias(Yii::$app->zoo->elementsPath)))); $elements = []; foreach ($files as $file) { $elements[$file] = Inflector::camel2words($file); } return $elements; }
public function actionIndex() { foreach (FileHelper::findFiles($this->module->getControllerPath()) as $file) { $id = lcfirst(substr(basename($file), 0, -14)); $name = Inflector::camel2words($id); $route = ['/' . $this->module->id . '/' . Inflector::camel2id($name)]; $controllers[$name] = $route; } return $this->render('index', ['controllers' => $controllers]); }
/** * @hass-todo */ public function actionIndex() { $namespaces = \HassClassLoader::getHassCoreFile(); $result = []; foreach ($namespaces as $namespace => $dir) { $controllerDir = $dir . DIRECTORY_SEPARATOR . "controllers"; if (!is_dir($controllerDir)) { continue; } $files = FileHelper::findFiles($controllerDir); $moduleId = trim(substr($namespace, strrpos(rtrim($namespace, "\\"), "\\")), "\\"); $result[$moduleId]["module"] = $moduleId; $result[$moduleId]["permissions"] = []; foreach ($files as $file) { $childDir = rtrim(pathinfo(substr($file, strpos($file, "controllers") + 12), PATHINFO_DIRNAME), "."); if ($childDir) { $class = $namespace . "controllers\\" . str_replace("/", "\\", $childDir) . "\\" . rtrim(basename($file), ".php"); } else { $class = $namespace . "controllers\\" . rtrim(basename($file), ".php"); } $controllerId = Inflector::camel2id(str_replace("Controller", "", pathinfo($file, PATHINFO_FILENAME))); $reflect = new \ReflectionClass($class); $methods = $reflect->getMethods(\ReflectionMethod::IS_PUBLIC); /** @var \ReflectionMethod $method */ foreach ($methods as $method) { if (!StringHelper::startsWith($method->name, "action")) { continue; } if ($method->name == "actions") { $object = \Yii::createObject(["class" => $class], [$controllerId, $moduleId]); $actions = $method->invoke($object); foreach ($actions as $actionId => $config) { $route = $moduleId . "/" . $controllerId . "/" . $actionId; if ($childDir) { $route = $moduleId . "/" . $childDir . "/" . $controllerId . "/" . $actionId; } $result[$moduleId]["permissions"][$route] = ["type" => Item::TYPE_PERMISSION, "description" => $controllerId . "-" . Inflector::camel2words($actionId)]; } continue; } $actionId = Inflector::camel2id(substr($method->name, 6)); $route = $moduleId . "/" . $controllerId . "/" . $actionId; if ($childDir) { $route = $moduleId . "/" . $childDir . "/" . $controllerId . "/" . $actionId; } $result[$moduleId]["permissions"][$route] = ["type" => Item::TYPE_PERMISSION, "description" => $controllerId . "-" . Inflector::camel2words(substr($method->name, 6))]; } } } $result["super"] = ['module' => 'SUPER_PERMISSION', 'permissions' => array(\hass\rbac\Module::SUPER_PERMISSION => array('type' => Item::TYPE_PERMISSION, 'description' => 'SUPER_PERMISSION'))]; $result = "<?php \n return " . var_export($result, true) . ";"; file_put_contents(dirname(__DIR__) . "/permissions.php", $result); return $this->render("index"); }
/** * @inheritdoc */ protected function convertToLogical($value, $attribute) { if ($this->isEmpty($value)) { return null; } if (isset($this->enum[$value])) { return $this->enum[$value]; } $names = static::names($this->owner, $this->enumPrefix); $str = isset($names[$value]) ? $names[$value] : ''; return $this->toWord ? Inflector::camel2words(strtolower($str)) : $str; }
public function buildUniqueRules(&$ruleList) { foreach ($this->uniqueColumnList as $columnInOneConstraintList) { if (count($columnInOneConstraintList) > 1) { $columnListAsStr = []; foreach ($columnInOneConstraintList as $columnName) { $columnListAsStr[] = \yii\helpers\Inflector::camel2words($columnName); } $ruleList[] = [$columnInOneConstraintList, 'unique', 'targetAttribute' => $columnInOneConstraintList, 'message' => 'The combination of ' . implode(' and ', $columnListAsStr) . ' has already been taken.']; } else { $ruleList[] = [$columnInOneConstraintList, 'unique']; } } }
/** * Create a new ActiveWindow class based on you properties. */ public function actionCreate() { $name = $this->prompt("Please enter a name for the Active Window:", ['required' => true]); $className = $this->createClassName($name, $this->suffix); $moduleId = $this->selectModule(['text' => 'What module should ' . $className . ' belong to?', 'onlyAdmin' => true]); $module = Yii::$app->getModule($moduleId); $folder = $module->basePath . DIRECTORY_SEPARATOR . 'aws'; $file = $folder . DIRECTORY_SEPARATOR . $className . '.php'; $content = $this->view->render('@luya/console/commands/views/aw/create.php', ['className' => $className, 'namespace' => $module->getNamespace() . '\\aws', 'luya' => $this->getLuyaVersion(), 'moduleId' => $moduleId, 'alias' => Inflector::humanize(Inflector::camel2words($className))]); FileHelper::createDirectory($folder); if (FileHelper::writeFile($file, $content)) { return $this->outputSuccess("The Active Window file '{$file}' has been writtensuccessfull."); } return $this->outputError("Error while writing the Actice Window file '{$file}'."); }
public function actionIndex() { $parent = $this->module; $modules = []; foreach ($parent->modules as $id => $module) { $module = $parent->getModule($id); $class = new \ReflectionClass($module); $comment = strtr(trim(preg_replace('/^\\s*\\**( |\\t)?/m', '', trim($class->getDocComment(), '/'))), "\r", ''); if (preg_match('/^\\s*@\\w+/m', $comment, $matches, PREG_OFFSET_CAPTURE)) { $comment = trim(substr($comment, 0, $matches[0][1])); } $modules[$module->uniqueId] = ['name' => \yii\helpers\Inflector::camel2words($module->id), 'comment' => $comment]; } return $this->render('index', ['modules' => $modules]); }
/** * @return array */ public function getActions() { $instance = $this->createInstance(); $reflection = new \ReflectionClass($instance); $actions = []; /** @var VerbFilter $filter */ $filter = ArrayHelper::getValue($instance->behaviors(), 'verbs'); /** @var ReflectionMethod $method */ foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if ($route = $this->extractRoute($method)) { $docParser = new DocParser(['source' => $method->getDocComment()]); $actions[] = new ActionModel(['controllerModel' => $this, 'verbs' => $filter ? ArrayHelper::getValue($filter, ['actions', $route], []) : ['get'], 'route' => $this->route . '/' . $route, 'description' => $docParser->getDescription(), 'label' => Inflector::camel2words($route)]); } } return $actions; }
/** * @inherit * * 针对键值相关命令, 需要根据键对应的业务标识选择指定的数据库 */ public function __call($name, $params) { $key = false; $busiName = null; $redisCommand = strtoupper(Inflector::camel2words($name, false)); if (in_array($redisCommand, $this->keyValueCommands)) { if (is_array($params)) { $key = $params[0]; } if ($key && ($busiName = $this->parseBusiName($key))) { $this->setDB($busiName); } else { throw new \OutOfRangeException('Business key parse failed'); } } return parent::__call($name, $params); }
public static function statusList($className, $extra = []) { if (!isset(static::$_maps_list[$className])) { $ref = new ReflectionClass($className); static::$_maps_list[$className] = []; foreach ($ref->getConstants() as $key => $value) { if (strpos($key, 'STATUS_') === 0) { static::$_maps_list[$className][$value] = Inflector::camel2words(strtolower(substr($key, 7))); } } } $result = static::$_maps_list[$className]; foreach ($extra as $key => $value) { $result[$key] = $value; } ksort($result); return $result; }
/* @var $this yii\web\View */ /* @var $model <?php echo ltrim($generator->modelClass, '\\'); ?> */ $this->title = <?php echo $generator->generateString('Update {modelClass}: ', ['modelClass' => Inflector::camel2words(StringHelper::basename($generator->modelClass))]); ?> . ' ' . $model-><?php echo $generator->getNameAttribute(); ?> ; $this->params['breadcrumbs'][] = ['label' => <?php echo $generator->generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))); ?> , 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model-><?php echo $generator->getNameAttribute(); ?> , 'url' => ['view', <?php echo $urlParams; ?> ]]; $this->params['breadcrumbs'][] = <?php echo $generator->generateString('Update'); ?> ; ?>
<?php if (!empty($generator->searchModelClass)) { echo " <?php " . ($generator->indexWidgetType === 'grid' ? "// " : ""); ?> echo $this->render('_search', ['model' => $searchModel]); ?> <?php } ?> <p> <?php echo "<?= "; ?> Html::a(<?php echo $generator->generateString('Create ' . Inflector::camel2words(StringHelper::basename($generator->modelClass))); ?> , ['create'], ['class' => 'btn btn-success']) ?> </p> <?php if ($generator->indexWidgetType === 'grid') { ?> <?php echo "<?= "; ?> GridView::widget([ 'dataProvider' => $dataProvider, <?php echo !empty($generator->searchModelClass) ? "'filterModel' => \$searchModel,\n 'columns' => [\n" : "'columns' => [\n"; ?>
Html::encode($this->title) ?></h1> <?php if (!empty($generator->searchModelClass)) { echo " <?php " . ($generator->indexWidgetType === 'grid' ? "// " : ""); ?> echo $this->render('_search', ['model' => $searchModel]); ?> <?php } ?> <p> <?php echo "<?= "; ?> Html::a(<?php echo $generator->generateString('Create {modelClass}', ['modelClass' => Inflector::camel2words(StringHelper::basename($generator->modelClass))]); ?> , ['create'], ['class' => 'btn btn-success']) ?> </p> <?php if ($generator->indexWidgetType === 'grid') { ?> <?php echo "<?= "; ?> GridView::widget([ 'dataProvider' => $dataProvider, <?php echo !empty($generator->searchModelClass) ? "'filterModel' => \$searchModel,\n 'columns' => [\n" : "'columns' => [\n"; ?>
<?php if (isset($this->blocks['content-header'])) { ?> <h1><?php echo $this->blocks['content-header']; ?> </h1> <?php } else { ?> <h1> <?php if ($this->title !== null) { echo \yii\helpers\Html::encode($this->title); } else { echo \yii\helpers\Inflector::camel2words(\yii\helpers\Inflector::id2camel($this->context->module->id)); echo $this->context->module->id !== \Yii::$app->id ? '<small>Module</small>' : ''; } ?> </h1> <?php } ?> <?php echo Breadcrumbs::widget(['links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]); ?> </section> <section class="content"> <?php
echo $generator->generateString(Inflector::camel2words($rel[1])); ?> ), 'content' => $this->render('_view', [ 'all' => false, ]), ], <?php foreach ($relations as $name => $rel) { ?> <?php if ($rel[2] && isset($rel[3]) && !in_array($name, $generator->skippedRelations)) { ?> [ 'label' => '<i class="glyphicon glyphicon-user"></i> '. Html::encode(<?php echo $generator->generateString(Inflector::camel2words($rel[1])); ?> ), 'content' => $this->render('_data<?php echo $rel[1]; ?> ', [ 'model' => $model, 'row' => $model-><?php echo $name; ?> , ]), ], <?php }
/** * Wizzard to create a new CMS block. * * @return number */ public function actionCreate() { if (empty($this->type)) { Console::clearScreenBeforeCursor(); $this->type = $this->select('Do you want to create an app or module Block?', [self::TYPE_APP => 'Creates a project block inside your @app Namespace (casual).', self::TYPE_MODULE => 'Creating a block inside a later specified Module.']); } if ($this->type == self::TYPE_MODULE && count($this->getModuleProposal()) === 0) { return $this->outputError('Your project does not have Project-Modules registered!'); } if (empty($this->moduleName) && $this->type == self::TYPE_MODULE) { $this->moduleName = $this->select('Choose a module to create the block inside:', $this->getModuleProposal()); } if (empty($this->blockName)) { $this->blockName = $this->prompt('Insert a name for your Block (e.g. HeadTeaser):', ['required' => true]); } if ($this->isContainer === null) { $this->isContainer = $this->confirm("Do you want to add placeholders to your block that serve as a container for nested blocks?", false); } if ($this->cacheEnabled === null) { $this->cacheEnabled = $this->confirm("Do you want to enable the caching for this block or not?", true); } if ($this->config === null) { $this->config = ['vars' => [], 'cfgs' => [], 'placeholders' => []]; $doConfigure = $this->confirm('Would you like to configure this Block? (vars, cfgs, placeholders)', false); if ($doConfigure) { $doVars = $this->confirm('Add new Variable (vars)?', false); $i = 1; while ($doVars) { $item = $this->varCreator('Variabel (vars) #' . $i, 'var'); $this->phpdoc[] = '{{vars.' . $item['var'] . '}}'; $this->viewFileDoc[] = '$this->varValue(\'' . $item['var'] . '\');'; $this->config['vars'][] = $item; $doVars = $this->confirm('Add one more?', false); ++$i; } $doCfgs = $this->confirm('Add new Configuration (cgfs)?', false); $i = 1; while ($doCfgs) { $item = $this->varCreator('Configration (cfgs) #' . $i, 'cfg'); $this->phpdoc[] = '{{cfgs.' . $item['var'] . '}}'; $this->viewFileDoc[] = '$this->cfgValue(\'' . $item['var'] . '\');'; $this->config['cfgs'][] = $item; $doCfgs = $this->confirm('Add one more?', false); ++$i; } $doPlaceholders = $this->confirm('Add new Placeholder (placeholders)?', false); $i = 1; while ($doPlaceholders) { $item = $this->placeholderCreator('Placeholder (placeholders) #' . $i); $this->phpdoc[] = '{{placeholders.' . $item['var'] . '}}'; $this->viewFileDoc[] = '$this->placeholderValue(\'' . $item['var'] . '\');'; $this->config['placeholders'][] = $item; $doPlaceholders = $this->confirm('Add one more?', false); ++$i; } } } $folder = $this->getFileBasePath() . DIRECTORY_SEPARATOR . 'blocks'; $filePath = $folder . DIRECTORY_SEPARATOR . $this->blockName . '.php'; sort($this->phpdoc); $content = $this->view->render('@luya/console/commands/views/block/create_block.php', ['namespace' => $this->getFileNamespace(), 'className' => $this->blockName, 'name' => Inflector::camel2words($this->blockName), 'type' => $this->type, 'module' => $this->moduleName, 'isContainer' => $this->isContainer, 'cacheEnabled' => $this->cacheEnabled, 'config' => $this->config, 'phpdoc' => $this->phpdoc, 'extras' => $this->extras, 'luyaText' => $this->getGeneratorText('block/create')]); if ($this->dryRun) { return $content; } if (FileHelper::createDirectory($folder) && FileHelper::writeFile($filePath, $content)) { // generate view file based on block object view context $object = Yii::createObject(['class' => $this->getFileNamespace() . '\\' . $this->blockName]); $viewsFolder = Yii::getAlias($object->getViewPath()); $viewFilePath = $viewsFolder . DIRECTORY_SEPARATOR . $object->getViewFileName('php'); if (FileHelper::createDirectory($viewsFolder) && FileHelper::writeFile($viewFilePath, $this->generateViewFile($this->blockName))) { $this->outputInfo('View file for the block has been created: ' . $viewFilePath); } return $this->outputSuccess("Block {$this->blockName} has been created: " . $filePath); } return $this->outputError("Error while creating block '{$filePath}'"); }
$gridName = $pivotName; } else { $pjaxId = "pjax-{$name}"; $gridRelation = $relation; $gridName = $name; } $output = $generator->relationGrid([$gridRelation, $gridName, $showAllRecords]); // render relation grid if (!empty($output)) { echo "\t<?php Pjax::begin(['id'=>'pjax-{$name}','linkSelector'=>'#pjax-{$name} ul.pagination a']) ?>\n\n"; echo "\t<?= " . str_replace("\n", "\n\t", $output) . "?>\n\n"; echo "\t<?php Pjax::end() ?>\n\n"; } echo "\t<?php \$this->endBlock() ?>\n\n"; // build tab items $label = Inflector::camel2words($name); $items .= <<<EOS [ 'label' => '<small><span class="glyphicon glyphicon-paperclip"></span> {$label}</small>', 'content' => \$this->blocks['{$name}'], 'active' => false, ], EOS; } ?> <?php echo "<?= "; ?> \yii\bootstrap\Tabs::widget([
/** * Parses and returns the attribute * * @param string|array $attribute the attribute item configuration * * @return array the parsed attribute item configuration * @throws InvalidConfigException */ protected function parseAttributeItem($attribute) { if (is_string($attribute)) { if (!preg_match('/^([\\w\\.]+)(:(\\w*))?(:(.*))?$/', $attribute, $matches)) { throw new InvalidConfigException('The attribute must be specified in the format of "attribute", "attribute:format" or ' . '"attribute:format:label"'); } $attribute = ['attribute' => $matches[1], 'format' => isset($matches[3]) ? $matches[3] : 'text', 'label' => isset($matches[5]) ? $matches[5] : null]; } if (!is_array($attribute)) { throw new InvalidConfigException('The attribute configuration must be an array.'); } if (isset($attribute['columns'])) { foreach ($attribute['columns'] as $j => $child) { $attr = $this->parseAttributeItem($child); if (isset($attr['visible']) && !$attr['visible']) { unset($attribute['columns'][$j]); continue; } $attribute['columns'][$j] = $attr; } return $attribute; } $attr = ArrayHelper::getValue($attribute, 'updateAttr'); if ($attr && !ctype_alnum(str_replace('_', '', $attr))) { throw new InvalidConfigException("The 'updateAttr' name '{$attr}' is invalid."); } $attr = ArrayHelper::getValue($attribute, 'attribute', ''); if ($attr && strpos($attr, '.') !== false) { throw new InvalidConfigException("The attribute '{$attr}' is invalid. You cannot directly pass relational attributes in string format " . "within '\\kartik\\widgets\\DetailView'. Instead use the array format with 'attribute' property " . "set to base field, and the 'value' property returning the relational data. You can also override the " . "widget 'model' settings by setting the 'viewModel' and / or 'editModel' at the attribute array level."); } if (!isset($attribute['format'])) { $attribute['format'] = 'text'; } if (isset($attribute['attribute'])) { $attributeName = $attribute['attribute']; $model = !empty($attribute['viewModel']) && $attribute['viewModel'] instanceof Model ? $attribute['viewModel'] : $this->model; if (!isset($attribute['label'])) { $attribute['label'] = $model instanceof Model ? $model->getAttributeLabel($attributeName) : Inflector::camel2words($attributeName, true); } if (!array_key_exists('value', $attribute)) { $attribute['value'] = ArrayHelper::getValue($model, $attributeName); } } elseif (!isset($attribute['label']) || !array_key_exists('value', $attribute)) { if (ArrayHelper::getValue($attribute, 'group', false) || isset($attribute['columns'])) { $attribute['value'] = ''; return $attribute; } throw new InvalidConfigException('The attribute configuration requires the "attribute" element to determine the value and display label.'); } return $attribute; }
/** * Generates a user friendly attribute label based on the give attribute name. * This is done by replacing underscores, dashes and dots with blanks and * changing the first letter of each word to upper case. * For example, 'department_name' or 'DepartmentName' will generate 'Department Name'. * @param string $name the column name * @return string the attribute label */ public function generateAttributeLabel($name) { return Inflector::camel2words($name, true); }
/** * Generates the attribute label * * @param $attribute * * @return string */ protected function getAttributeLabel($attribute) { $provider = $this->gridOptions['dataProvider']; /** @var Model $model */ if ($provider instanceof yii\data\ActiveDataProvider && $provider->query instanceof yii\db\ActiveQueryInterface) { $model = new $provider->query->modelClass(); return $model->getAttributeLabel($attribute); } else { $models = $provider->getModels(); if (($model = reset($models)) instanceof Model) { return $model->getAttributeLabel($attribute); } else { return Inflector::camel2words($attribute); } } }