public function getModelSubDir($model) { $pk = $model::primaryKey(); $id = array_shift($pk); $modelName = $this->getShortClass($model); $modelDir = \yii\helpers\Inflector::pluralize($modelName) . '/' . $modelName . $model->{$id}; return $modelDir; }
public function testPluralize() { $testData = ['move' => 'moves', 'foot' => 'feet', 'child' => 'children', 'human' => 'humans', 'man' => 'men', 'staff' => 'staff', 'tooth' => 'teeth', 'person' => 'people', 'mouse' => 'mice', 'touch' => 'touches', 'hash' => 'hashes', 'shelf' => 'shelves', 'potato' => 'potatoes', 'bus' => 'buses', 'test' => 'tests', 'car' => 'cars']; foreach ($testData as $testIn => $testOut) { $this->assertEquals($testOut, Inflector::pluralize($testIn)); $this->assertEquals(ucfirst($testOut), ucfirst(Inflector::pluralize($testIn))); } }
public function init() { if (!$this->modelClass) { $this->modelClass = Inflector::pluralize($this->id); } \Yii::$app->request->getRawBody(); \Yii::$app->getResponse()->getHeaders()->add('Access-Control-Allow-Origin', '*'); parent::init(); }
public function getModelSubDir() { $modelName = $this->getShortClass($this->owner); $modelDir = Inflector::pluralize($modelName) . '/' . $modelName . $this->owner->id; return $modelDir; }
public function getModelSubDir($model) { $modelName = $this->getShortClass($model); $modelDir = \yii\helpers\Inflector::pluralize($modelName) . '/' . $modelName . $model->id; return $modelDir; }
/** * @return string the name of the index this record is stored in. */ public static function index() { return Inflector::pluralize(Inflector::camel2id(StringHelper::basename(get_called_class()), '-')); }
/** * @inheritdoc */ public function init() { if (empty($this->controller)) { throw new InvalidConfigException('"controller" must be set.'); } $controllers = []; foreach ((array) $this->controller as $urlName => $controller) { if (is_integer($urlName)) { $urlName = $this->pluralize ? Inflector::pluralize($controller) : $controller; } $controllers[$urlName] = $controller; } $this->controller = $controllers; $this->prefix = trim($this->prefix, '/'); parent::init(); }
/** * @return string */ public function getPluralName() { return $this->_pluralName ?: Inflector::titleize(Inflector::pluralize($this->_type)); }
/** * Retrieves heading * @param boolean $plural */ public function getHeading($plural = false) { $headingKey = sprintf('heading_%s', $this->getClassid(self::RK_MODEL_CM, false, '_')); if ($plural) { return self::$generator->generateString(Inflector::pluralize($headingKey)); } return self::$generator->generateString($headingKey); }
echo lcfirst($column[4][0]); ?> -><?php echo $column[4][1]; ?> : '', <?php } } } elseif ($column[2] != 'main') { ?> isset($this->model-><?php echo lcfirst(Inflector::pluralize($column[0])); ?> [0]) ? $this->model-><?php echo lcfirst(Inflector::pluralize($column[0])); ?> [0]-><?php echo $column[1]->name; ?> : '', <?php } elseif (in_array($column[3], [$generator::TYPE_DATE_AUTO, $generator::TYPE_DATE_INPUT])) { ?> Yii::$app->formatter->asDatetime($this->model-><?php echo $column[1]->name; ?> , I18N::getDateFormat()), <?php } elseif ($column[3] == $generator::TYPE_IMAGE_INPUT) { ?>
public function loadAll($POST, $skippedRelations = []) { if ($this->load($POST)) { $shortName = StringHelper::basename(get_class($this)); $relData = $this->getRelationData(); foreach ($POST as $key => $value) { if ($key != $shortName && strpos($key, '_') === false) { /* @var $AQ ActiveQuery */ /* @var $this ActiveRecord */ /* @var $relObj ActiveRecord */ $isHasMany = is_array($value) && is_array(current($value)); $relName = $isHasMany ? lcfirst(Inflector::pluralize($key)) : lcfirst($key); if (in_array($relName, $skippedRelations) || !array_key_exists($relName, $relData)) { continue; } $AQ = $this->getRelation($relName); $relModelClass = $AQ->modelClass; $relPKAttr = $relModelClass::primaryKey(); $isManyMany = count($relPKAttr) > 1; if ($isManyMany) { $container = []; foreach ($value as $relPost) { if (array_filter($relPost)) { $condition = []; $condition[$relPKAttr[0]] = $this->primaryKey; foreach ($relPost as $relAttr => $relAttrVal) { if (in_array($relAttr, $relPKAttr)) { $condition[$relAttr] = $relAttrVal; } } $relObj = $relModelClass::findOne($condition); if (is_null($relObj)) { $relObj = new $relModelClass(); } $relObj->load($relPost, ''); $container[] = $relObj; } } $this->populateRelation($relName, $container); } else { if ($isHasMany) { $container = []; foreach ($value as $relPost) { if (array_filter($relPost)) { /* @var $relObj ActiveRecord */ $relObj = empty($relPost[$relPKAttr[0]]) ? new $relModelClass() : $relModelClass::findOne($relPost[$relPKAttr[0]]); $relObj->load($relPost, ''); $container[] = $relObj; } } $this->populateRelation($relName, $container); } else { $relObj = empty($value[$relPKAttr[0]]) ? new $relModelClass() : $relModelClass::findOne($value[$relPKAttr[0]]); $relObj->load($value, ''); $this->populateRelation($relName, $relObj); } } } } return true; } else { return false; } }
?> /* @var $dataProvider yii\data\ActiveDataProvider */ //$this->title = <?php echo $generator->generateString(Inflector::pluralize($nameModel)); ?> ; //$this->params['breadcrumbs'][] = $this->title; ?> <div class="<?php echo Inflector::camel2id(StringHelper::basename($generator->modelClass)); ?> -index box"> <div class="box-header with-border"> <h1 class='box-title'><?php echo Inflector::pluralize($nameModel); ?> </h1> </div> <div class="box-body table-responsive"> <?php if (!empty($generator->searchModelClass)) { echo " <?php " . ($generator->indexWidgetType === 'grid' ? "// " : ""); ?> echo $this->render('_search', ['model' => $searchModel]); ?> <?php } ?> <p>
/** * Generate a relation name for the specified table and a base name. * @param string $key a base name that the relation name may be generated from * @param boolean $multiple whether this is a has-many relation * @return string the relation name */ protected function generateRelationName($key, $multiple) { if (!empty($key) && substr_compare($key, 'id', -2, 2, true) === 0 && strcasecmp($key, 'id')) { $key = rtrim(substr($key, 0, -2), '_'); } if ($multiple) { $key = Inflector::pluralize($key); } return Inflector::id2camel($key, '_'); }
* @var yii\web\View $this * @var <?php echo ltrim($generator->modelClass, '\\'); ?> $model */ $this->title = <?php echo $generator->generateString('Create'); ?> ; $this->params['breadcrumbs'][] = ['label' => Yii::t('<?php echo $generator->modelMessageCategory; ?> ', '<?php echo Inflector::pluralize($modelName); ?> '), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="giiant-crud <?php echo Inflector::camel2id(StringHelper::basename($generator->modelClass), '-', true); ?> -create"> <h1> <?php echo "<?= Yii::t('{$generator->modelMessageCategory}', '{$modelName}') ?>\n"; ?> <small> <?php
/** * Should return an array with single and plural form of model name, e.g. * * ```php * return ['User', 'Users']; * ``` * * @return array */ public static function labels() { $class = new ReflectionClass(static::className()); $class = $class->getShortName(); return [$class, Inflector::pluralize($class)]; }
protected function getSubDur() { return \yii\helpers\Inflector::pluralize($this->modelName) . '/' . $this->modelName . $this->itemId; }
public static function modelTitle() { return <?php echo $generator->generateString(Inflector::camel2words($className)); ?> ; } /** * Returns plural form of the model title, ex.: 'Persons', 'Books' * @return string */ public static function modelTitlePlural() { return <?php echo $generator->generateString(Inflector::camel2words(Inflector::pluralize($className))); ?> ; } <?php } ?> /** * @inheritdoc */ public function rules() { return [<?php echo "\n " . implode(",\n ", $rules) . "\n "; ?>
'; } /** * Alias name of table for crud viewsLists all Area models. * Change the alias name manual if needed later * @return string */ public function getAliasModel($plural=false) { if($plural){ return Yii::t('<?php echo $generator->messageCategory; ?> ', '<?php echo Inflector::pluralize(StringHelper::basename($className)); ?> '); }else{ return Yii::t('<?php echo $generator->messageCategory; ?> ', '<?php echo StringHelper::basename($className); ?> '); } } <?php if (isset($translation)) { ?>
public static function generatePluralHumanName($modelClass) { return Yii::t('app', Inflector::pluralize(Inflector::camel2words(StringHelper::basename($modelClass)))); }
/* @var $this yii\web\View */ /* @var $model <?php echo ltrim($generator->modelClass, '\\'); ?> */ $this->title = <?php echo $generator->generateString('Update {modelClass}: ', ['modelClass' => Inflector::camel2words($generator->getModelNameForView())]); ?> . ' ' . $model-><?php echo $generator->getNameAttribute(); ?> ; $this->params['breadcrumbs'][] = ['label' => <?php echo $generator->generateString(Inflector::pluralize(Inflector::camel2words($generator->getModelNameForView()))); ?> , 'url' => ['index']]; $this->params['breadcrumbs'][] = <?php echo $generator->generateString('Update'); ?> ; ?> <div class="<?php echo Inflector::camel2id($generator->getModelNameForView()); ?> -update"> <h1><?php echo "<?php echo "; ?>
<?php use yii\helpers\Inflector; use yii\helpers\StringHelper; /* * @var yii\web\View $this * @var schmunk42\giiant\generators\crud\Generator $generator */ $urlParams = $generator->generateUrlParams(); $nameAttribute = $generator->getNameAttribute(); /** @var \yii\db\ActiveRecord $model */ $model = new $generator->modelClass(); $model->setScenario('crud'); $modelName = Inflector::pluralize(StringHelper::basename($model::className())); $safeAttributes = $model->safeAttributes(); if (empty($safeAttributes)) { /** @var \yii\db\ActiveRecord $model */ $model = new $generator->modelClass(); $safeAttributes = $model->safeAttributes(); if (empty($safeAttributes)) { $safeAttributes = $model->getTableSchema()->columnNames; } } echo "<?php\n"; ?> use yii\helpers\Html; use yii\helpers\Url; use <?php echo $generator->indexWidgetType === 'grid' ? 'yii\\grid\\GridView' : 'yii\\widgets\\ListView'; ?>
/** * Create rules * * @param array $resources * @param array $parents */ protected function createRules($resources, $parents = []) { $prefix = $this->prefix; foreach ($parents as $urlName => $idPattern) { $prefix .= '/' . $urlName . '/' . $idPattern; } foreach ($resources as $resource) { $only = array_flip($resource['only']); $except = array_flip($resource['except']); $extra = array_flip(array_values($resource['extraPatterns'])); $patterns = $resource['extraPatterns'] + $this->patterns; $controller = $resource['controller']; $urlName = $resource['name']; if ($this->pluralize) { $urlName = Inflector::pluralize($urlName); } $resPrefix = trim($prefix . '/' . $urlName, '/'); $resParents = $parents; foreach ($patterns as $pattern => $action) { if (!isset($except[$action]) && (empty($only) || isset($only[$action])) || isset($extra[$action])) { $tokens = [$resource['idToken'] => sprintf('<%s:%s>', $resource['idName'], $resource['idPattern'])]; $action = ltrim($this->routePrefix . '/' . $controller . '/' . $action, '/'); $rule = $this->createRule($pattern, $resPrefix, $action, $tokens); $urlIndex = join('.', array_merge(array_keys($resParents), [$urlName])); $this->urlToRules[$urlIndex][] = $rule; $this->controllerToRules[$controller][] = $rule; } } if (!empty($resource['resources'])) { $idName = lcfirst(Inflector::id2camel($resource['name'] . '-' . $resource['idName'])); $resParents[$urlName] = sprintf('<%s:%s>', $idName, $resource['idPattern']); $this->createRules($resource['resources'], $resParents); } } }
?> </div> </div> <?php echo '<?php $this->endBlock() ?>'; ?> <div class="<?php echo Inflector::camel2id(StringHelper::basename($generator->modelClass)); ?> -index"> <div class="ibox float-e-margins"> <div class="ibox-title"> <h5><?php echo '<?=Yii::t(\'app\',\'' . $generator->generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) . ' Listing\')?>'; ?> </h5> </div> <div class="ibox-content"> <form> <div class="input-group"> <input type="text" placeholder="<?php echo '<?=' . $generator->generateString('Search ' . Inflector::camel2id(StringHelper::basename($generator->modelClass))) . '?>'; ?> " class="input form-control" name="q" value="<?php echo '<?= isset($_GET[\'q\']) ? $_GET[\'q\'] : "" ?>'; ?> "> <span class="input-group-btn"> <button type="submit" class="btn btn btn-primary"><i class = "fa fa-search"></i> <?php
/** * Get model's plural name. * * @param string|\yii\db\ActiveRecord $model * @return string */ public function getPluralName($model) { if (is_string($model)) { $model = $this->loadModel($model); } if (!isset($model->adminNames)) { return Inflector::pluralize(Inflector::camel2words(StringHelper::basename($model->className()))); } else { return $model->adminNames[2]; } }
/** * Generate a relation name for the specified table and a base name. * @param array $relations the relations being generated currently. * @param \yii\db\TableSchema $table the table schema * @param string $key a base name that the relation name may be generated from * @param boolean $multiple whether this is a has-many relation * @return string the relation name */ protected function generateRelationName($relations, $table, $key, $multiple) { if (!empty($key) && substr_compare($key, 'id', -2, 2, true) === 0 && strcasecmp($key, 'id')) { $key = rtrim(substr($key, 0, -2), '_'); } if ($multiple) { $key = Inflector::pluralize($key); } $name = $rawName = Inflector::id2camel($key, '_'); $i = 0; while (isset($table->columns[lcfirst($name)])) { $name = $rawName . $i++; } while (isset($relations[$table->fullName][$name])) { $name = $rawName . $i++; } return $name; }
} ?> /* @var $this yii\web\View */ /* @var $model <?php echo ltrim($generator->modelClass, '\\'); ?> */ $this->title = <?php echo $generator->generateString(($table_comment ? $table_comment : Inflector::camel2words(StringHelper::basename($generator->modelClass))) . '新建'); ?> ; $this->params['breadcrumbs'][] = ['label' => <?php echo $generator->generateString(($table_comment ? $table_comment : Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) . '列表'); ?> , 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="col-md-12"> <!-- general form elements --> <div class="box box-primary <?php echo Inflector::camel2id(StringHelper::basename($generator->modelClass)); ?> -create"> <div class="box-header with-border"> <!-- <h3 class="box-title">Quick Example</h3> --> </div><!-- /.box-header -->
<?php $items = <<<EOS [ 'label' => '<span class="glyphicon glyphicon-asterisk"></span> {$label}', 'content' => \$this->blocks['{$generator->modelClass}'], 'active' => true, ], EOS; foreach ($generator->getModelRelations($generator->modelClass, ['has_many']) as $name => $relation) { echo "\t<?php \$this->beginBlock('{$name}'); ?>\n\n"; // get relation info $ prepare add button $model = new $generator->modelClass(); $showAllRecords = false; if ($relation->via !== null) { $pivotName = Inflector::pluralize($generator->getModelByTableName($relation->via->from[0])); $pivotRelation = $model->{'get' . $pivotName}(); $pivotPk = key($pivotRelation->link); $addButton = " <?= \\yii\\helpers\\Html::a('<span class=\"glyphicon glyphicon-link\"></span> Attach " . Inflector::singularize(Inflector::camel2words($name)) . "', ['" . $generator->createRelationRoute($pivotRelation, 'create') . "', '" . Inflector::singularize($pivotName) . "'=>['" . key($pivotRelation->link) . "'=>\$model->{$model->primaryKey()[0]}]], ['class'=>'btn btn-info btn-xs']) ?>\n"; } else { $addButton = ''; } // relation list, add, create buttons echo "\t<p class='pull-right'>\n"; echo "\t\t<?= \\yii\\helpers\\Html::a('<span class=\"glyphicon glyphicon-list\"></span> List All " . Inflector::camel2words($name) . "', ['" . $generator->createRelationRoute($relation, 'index') . "'], ['class'=>'btn text-muted btn-xs'] ) ?>\n"; // TODO: support multiple PKs, VarDumper? echo "\t\t<?= \\yii\\helpers\\Html::a('<span class=\"glyphicon glyphicon-plus\"></span> New " . Inflector::singularize(Inflector::camel2words($name)) . "', ['" . $generator->createRelationRoute($relation, 'create') . "', '" . Inflector::singularize($name) . "'=>['" . key($relation->link) . "'=>\$model->" . $model->primaryKey()[0] . "]], ['class'=>'btn btn-success btn-xs']) ?>\n"; echo $addButton; echo "\t</p>\n\n"; echo "\t<div class='clearfix'></div>\n\n"; // render pivot grid
/* @var $this yii\web\View */ <?php echo !empty($generator->searchModelClass) ? "/* @var \$searchModel " . ltrim($generator->searchModelClass, '\\') . " */\n" : ''; ?> /* @var $dataProvider yii\data\ActiveDataProvider */ use yii\helpers\Html; use kartik\export\ExportMenu; use <?php echo $generator->indexWidgetType === 'grid' ? "kartik\\grid\\GridView;" : "yii\\widgets\\ListView;"; ?> $this->title = <?php echo $generator->pluralize ? $generator->generateString(Inflector::pluralize(Inflector::camel2words($baseModelClass))) : $generator->generateString(Inflector::camel2words($baseModelClass)); ?> ; $this->params['breadcrumbs'][] = $this->title; $search = "$('.search-button').click(function(){ $('.search-form').toggle(1000); return false; });"; $this->registerJs($search); ?> <div class="<?php echo Inflector::camel2id($baseModelClass); ?> -index"> <h1><?php
/* @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'); ?> ; ?>
echo $generator->helperCrud->getClassid(CrudHelper::RK_MODEL_CM); ?> -form"> <?php echo "<?php "; ?> $form = ActiveForm::begin(); ?> <?php echo "<?= GxFlashHelper::alertValidation(\$model) ?>"; ?> <?php if ($generator->generateMutation) { echo "<?=\n \$form->field(\$model, " . ModelHelper::root($generator->helperModel->getClass(ModelHelper::RK_MODEL_CM)) . "::" . sprintf('%s%s', \dlds\giixer\Module::RELATION_NAME_PREFIX, strtoupper(Inflector::pluralize($generator->mutationSourceTableName))) . ")->widget(dlds\\rels\\widgets\\RelTabs::className(), [\n 'relView' => '/" . $generator->helperCrud->getClassid(CrudHelper::RK_MODEL_CM) . "/crud/relations/" . Inflector::camel2id(StringHelper::basename($generator->mutationJoinTableName)) . "',\n 'header' => '" . lcfirst(Inflector::classify($generator->mutationSourceTableName)) . ".title',\n 'form' => \$form,\n ])->label(false);\n ?>"; ?> <?php } ?> <?php foreach ($columnNames as $attribute) { if (isset($safeAttributes[$attribute]) && !$safeAttributes[$attribute]->isPrimaryKey && $attribute != $generator->sortableColumnAttribute) { echo "<?= " . $generator->generateActiveField($attribute) . " ?>\n\n"; } } ?> <div class="form-group"> <?php