当前位置: 首页>>代码示例>>PHP>>正文


PHP Inflector::humanize方法代码示例

本文整理汇总了PHP中yii\helpers\Inflector::humanize方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::humanize方法的具体用法?PHP Inflector::humanize怎么用?PHP Inflector::humanize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\helpers\Inflector的用法示例。


在下文中一共展示了Inflector::humanize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: api_items

 public function api_items($slug)
 {
     $menu = MenuItem::find()->where(['route_string' => $slug])->one();
     if (!$menu) {
         $menuItem = new MenuItem(['name' => Inflector::humanize($slug), 'url' => $slug]);
         $menuItem->makeRoot();
     }
     return $this->formatItem($menu ? $menu->children : []);
 }
开发者ID:qwestern,项目名称:easyii-menu-module,代码行数:9,代码来源:Menu.php

示例2: init

 public function init()
 {
     if (!$this->name) {
         $this->name = Inflector::humanize($this->id);
     }
     if (!$this->controller instanceof UserController) {
         throw new InvalidParamException(\Yii::t('app', 'This action is designed to work with: {controller}', ['controller' => UserController::className()]));
     }
     $this->defaultView = $this->id;
     if ($this->viewName) {
         $this->defaultView = $this->viewName;
     }
     parent::init();
 }
开发者ID:Liv1020,项目名称:cms,代码行数:14,代码来源:UserAction.php

示例3: init

 public function init()
 {
     //Если название не задано, покажем что нибудь.
     if (!$this->name) {
         $this->name = Inflector::humanize($this->id);
     }
     if (!$this->controller instanceof AdminController) {
         throw new InvalidParamException(\Yii::t('app', 'This action is designed to work with the controller: ') . AdminController::className());
     }
     $this->defaultView = $this->id;
     if ($this->viewName) {
         $this->defaultView = $this->viewName;
     }
     parent::init();
 }
开发者ID:Liv1020,项目名称:cms,代码行数:15,代码来源:AdminAction.php

示例4: actionCreate

 /**
  * 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}'.");
 }
开发者ID:aekkapun,项目名称:luya,代码行数:18,代码来源:ActiveWindowController.php

示例5: getCoreMenus

 /**
  * Get core menu
  * @return array
  * @var $ids array has 'Menu Lable' => 'Controller' pairs
  */
 protected function getCoreMenus()
 {
     $mid = '/' . $this->getUniqueId() . '/';
     $ids = ['Assignments' => 'assignment', 'Roles' => 'role', 'Permissions' => 'permission', 'Routes' => 'route', 'Rules' => 'rule', 'Menus' => 'menu'];
     $config = components\Configs::instance();
     $result = [];
     foreach ($ids as $lable => $id) {
         if ($id !== 'menu' || $config->db !== null && $config->db->schema->getTableSchema($config->menuTable) !== null) {
             $result[$id] = ['label' => Yii::t('rbac-admin', $lable), 'url' => [$mid . $id]];
         }
     }
     foreach (array_keys($this->controllerMap) as $id) {
         $result[$id] = ['label' => Yii::t('rbac-admin', Inflector::humanize($id)), 'url' => [$mid . $id]];
     }
     return $result;
 }
开发者ID:orcsis,项目名称:yii2-admin,代码行数:21,代码来源:Module.php

示例6: actionIndex

 /**
  * Paginated endpoint for display all commodities from Eddb
  * @return array
  */
 public function actionIndex()
 {
     $query = Commodity::find();
     if (Yii::$app->request->get('category', false)) {
         // Find the requested category first
         $category = CommodityCategory::find()->where(['name' => Inflector::humanize(Yii::$app->request->get('category', NULL))])->one();
         if ($category === NULL) {
             throw new HttpException(404, 'Could not find commodities for the requested category');
         }
         // Append it to the query
         $query->andWhere(['category_id' => $category->id]);
     }
     // Also provide filtering by name
     if (Yii::$app->request->get('name', false)) {
         $query->andWhere(['name' => Inflector::humanize(Yii::$app->request->get('name', 'nothing'))]);
     }
     return ResponseBuilder::build($query, 'commodities', Yii::$app->request->get('sort', 'id'), Yii::$app->request->get('order', 'asc'));
 }
开发者ID:charlesportwoodii,项目名称:galnet-api,代码行数:22,代码来源:CommoditiesController.php

示例7: normalizeController

 private function normalizeController()
 {
     $controllers = [];
     $this->menus = [];
     $mid = '/' . $this->getUniqueId() . '/';
     $items = ArrayHelper::merge($this->getCoreItems(), $this->items);
     foreach ($items as $id => $config) {
         $label = Inflector::humanize($id);
         $visible = true;
         if (is_array($config)) {
             $label = ArrayHelper::remove($config, 'label', $label);
             $visible = ArrayHelper::remove($config, 'visible', true);
         }
         if ($visible) {
             $this->menus[] = ['label' => $label, 'url' => [$mid . $id]];
             $controllers[$id] = $config;
         }
     }
     $this->controllerMap = ArrayHelper::merge($this->controllerMap, $controllers);
 }
开发者ID:hscstudio,项目名称:yii2-heart,代码行数:20,代码来源:Module.php

示例8: init

 /**
  * Initializes the PNotify widget.
  * 
  * @param    void
  * @return   void
  * 
  * @since    1.0.0
  *
  */
 public function init()
 {
     parent::init();
     //assets
     PNotifyAsset::register($this->getView());
     //base objects
     $session = \Yii::$app->getSession();
     $flashes = $session->getAllFlashes();
     //go through all flashes
     foreach ($flashes as $type => $data) {
         //only for registered types
         if (in_array($type, $this->alertTypes)) {
             $data = (array) $data;
             //all mesages for this type
             foreach ($data as $i => $message) {
                 //show PNotify flash
                 Yii::$app->view->registerJs(static::populate('window.PNotifyObj.info("{title}", "{text}", "{type}");', ['title' => \yii\helpers\Inflector::humanize($type), 'text' => $message, 'type' => $type]));
             }
             $session->removeFlash($type);
         }
     }
 }
开发者ID:xunlight,项目名称:yii2-pnotify,代码行数:31,代码来源:PNotify.php

示例9: generateActiveField

 /**
  * Generates code for active field
  *
  * @param string $attribute
  *
  * @return string
  */
 public function generateActiveField($attribute)
 {
     $tableSchema = $this->getTableSchema();
     if ($tableSchema === false || !isset($tableSchema->columns[$attribute])) {
         if (preg_match('/^(password|pass|passwd|passcode)$/i', $attribute)) {
             return "\$form->field(\$model, '{$attribute}')->passwordInput()";
         } else {
             return "\$form->field(\$model, '{$attribute}')";
         }
     }
     $column = $tableSchema->columns[$attribute];
     if (in_array($column->dbType, ['smallint(1)', 'tinyint(1)'])) {
         return "\$form->field(\$model->loadDefaultValues(), '{$attribute}')->checkbox(['class'=>'b-switch'], false)";
     } elseif ($column->type === 'text') {
         return "\$form->field(\$model, '{$attribute}', ['enableClientValidation'=>false, 'enableAjaxValidation'=>false])->textarea(['rows' => 6])";
     } elseif ($this->isImage($column->name)) {
         return $this->_generateImageField($column);
     } elseif ($column->name === 'name') {
         return "\$form->field(\$model, '{$attribute}')->textInput(['maxlength' => 255, 'autofocus'=>\$model->isNewRecord ? true:false])";
     } elseif ($this->_isFk($column)) {
         return "\$form->field(\$model, '{$attribute}')\n\t\t->dropDownList(\n\t\t\tArrayHelper::map(" . Inflector::id2camel(rtrim($attribute, '_id'), '_') . "::find()->asArray()->all(), 'id', 'name'),\n\t\t\t['prompt'=>'']\n\t\t)";
     } elseif (stripos($column->name, 'price') !== false) {
         return "\$form->field(\$model, '{$attribute}',\n\t\t['inputTemplate' => '<div class=\"row\"><div class=\"col-sm-4\"><div class=\"input-group\">{input}<span class=\"input-group-addon\">€</span></div></div></div>',]\n\t)->textInput()";
     } else {
         if (preg_match('/^(password|pass|passwd|passcode)$/i', $column->name)) {
             $input = 'passwordInput';
         } else {
             $input = 'textInput';
         }
         if (is_array($column->enumValues) && count($column->enumValues) > 0) {
             $dropDownOptions = [];
             foreach ($column->enumValues as $enumValue) {
                 $dropDownOptions[$enumValue] = Inflector::humanize($enumValue);
             }
             return "\$form->field(\$model, '{$attribute}')->dropDownList(" . preg_replace("/\n\\s*/", ' ', VarDumper::export($dropDownOptions)) . ", ['prompt' => ''])";
         } elseif ($column->phpType !== 'string' || $column->size === null) {
             return "\$form->field(\$model, '{$attribute}')->{$input}()";
         } else {
             return "\$form->field(\$model, '{$attribute}')->{$input}(['maxlength' => {$column->size}])";
         }
     }
 }
开发者ID:webvimark,项目名称:generators,代码行数:49,代码来源:Generator.php

示例10: generateTabularActiveField

 public function generateTabularActiveField($tableName, $attribute)
 {
     $db = Yii::$app->get('db', false);
     $tableSchema = $db->getSchema()->getTableSchema($tableName);
     if ($tableSchema === false || !isset($tableSchema->columns[$attribute])) {
         if (preg_match('/^(password|pass|passwd|passcode)$/i', $attribute)) {
             return "\$form->field(\${$tableName}Mod, '{$attribute}', ['template' => '{input}{hint}{error}'])->passwordInput()";
         } else {
             return "\$form->field(\${$tableName}Mod, '{$attribute}', ['template' => '{input}{hint}{error}'])";
         }
     }
     $column = $tableSchema->columns[$attribute];
     if ($column->isPrimaryKey) {
         return "\$form->field(\${$tableName}Mod, \"[\$index]{$attribute}\", ['template' => '{input}{hint}{error}'])->textInput(['readonly' => true, 'style' => 'width : 60px']);";
     } elseif ($column->phpType === 'boolean') {
         return "\$form->field(\${$tableName}Mod, \"[\$index]{$attribute}\", ['template' => '{input}{hint}{error}'])->checkbox([], false)";
     } elseif ($column->type === 'smallint' && $column->size == 1) {
         return "\$form->field(\${$tableName}Mod, \"[\$index]{$attribute}\", ['template' => '{input}{hint}{error}'])->checkbox([], false)";
     } elseif ($column->type === 'text') {
         return "\$form->field(\${$tableName}Mod, \"[\$index]{$attribute}\", ['template' => '{input}{hint}{error}'])->textarea(['rows' => 6])";
     } elseif ($column->type === 'date') {
         return " ''\n                ?>\n                 <?php\n    echo \\kartik\\date\\DatePicker::widget([\n        'model' => \${$tableName}Mod,\n        'attribute' => \"[\$index]{$attribute}\",\n        'options' => ['placeholder' => 'Select date ...', 'class' => 'detaildatepicker'],\n        'pluginOptions' => [      \n            'todayHighlight' => true,\n            'autoclose'=>true,\n            'format' => 'yyyy-mm-dd'                    \n        ]\n]);\n    ?>\n    <?= ''\n             ";
     } elseif ($column->type === 'datetime') {
         return " ''\n                ?>\n                 <?php\n    echo kartik\\datetime\\DateTimePicker::widget([\n        'model' => \${$tableName}Mod,\n        'attribute' => \"[\$index]{$attribute}\",\n        'options' => ['placeholder' => 'Select time ...', 'class' => 'detaildatetimepicker'],\n        'pluginOptions' => [      \n            'todayHighlight' => true,\n            'autoclose'=>true,\n            'format' => 'yyyy-mm-dd hh:ii'                    \n        ]\n]);\n    ?>\n    <?= ''\n             ";
     } elseif ($column->type === 'integer' && $this->getForeignKeyInfo($attribute, $tableName) !== null) {
         $foreignKeyInfo = $this->getForeignKeyInfo($attribute, $tableName);
         $foreignTable = $foreignKeyInfo['foreignTable'];
         $foreignKey = $foreignKeyInfo['foreignKey'];
         $modGen = new yii\gii\generators\model\Generator();
         $className = $modGen->generateClassName($foreignTable);
         $foreignFieldName = $this->getNameAttributeOfTable($foreignTable);
         return "\$form->field(\${$tableName}Mod, \"[\$index]{$attribute}\", ['template' => '{input}{hint}{error}'])->dropDownList(\\yii\\helpers\\ArrayHelper::map(app\\models\\{$className}::find()->orderBy('{$foreignFieldName}')->asArray()->all(), '{$foreignKey}', '{$foreignFieldName}'), ['prompt' => 'Select...'])";
     } else {
         if (preg_match('/^(password|pass|passwd|passcode)$/i', $column->name)) {
             $input = 'passwordInput';
         } else {
             $input = 'textInput';
         }
         if (is_array($column->enumValues) && count($column->enumValues) > 0) {
             $dropDownOptions = [];
             foreach ($column->enumValues as $enumValue) {
                 $dropDownOptions[$enumValue] = Inflector::humanize($enumValue);
             }
             return "\$form->field(\${$tableName}Mod, \"[\$index]{$attribute}\", ['template' => '{input}{hint}{error}'])->dropDownList(" . preg_replace("/\n\\s*/", ' ', VarDumper::export($dropDownOptions)) . ", ['prompt' => ''])";
         } elseif ($column->phpType !== 'string' || $column->size === null) {
             return "\$form->field(\${$tableName}Mod, \"[\$index]{$attribute}\", ['template' => '{input}{hint}{error}'])->{$input}()";
         } else {
             return "\$form->field(\${$tableName}Mod, \"[\$index]{$attribute}\", ['template' => '{input}{hint}{error}'])->{$input}(['maxlength' => {$column->size}])";
         }
     }
 }
开发者ID:harlangray,项目名称:yii2-gii-advanced,代码行数:51,代码来源:Generator.php

示例11: generateActiveField

    /**
     * Generates code for active field
     * @param string $attribute
     * @return string
     */
    
    public function generateActiveField($attribute)
    {
        $tableSchema = $this->getTableSchema();
        
        
        if ($tableSchema === false || !isset($tableSchema->columns[$attribute])) {
            if (preg_match('/^(password|pass|passwd|passcode)$/i', $attribute)) {
                return "\$form->field(\$model, '$attribute')->passwordInput()";
            } else {
                return "\$form->field(\$model, '$attribute')";
            }
        }
        $column = $tableSchema->columns[$attribute];
       

        if ($column->phpType === 'boolean') {
            return "\$form->field(\$model, '$attribute')->checkbox()";
        } elseif ($column->type === 'text') {
            return "\$form->field(\$model, '$attribute')->textarea(['rows' => 6])";
        } else {
            if (preg_match('/^(password|pass|passwd|passcode|contrasena)$/i', $column->name)) {
                $input = 'passwordInput';
            } else {
                $input = 'textInput';
            }
            if (is_array($column->enumValues) && count($column->enumValues) > 0) {
                $dropDownOptions = [];
                foreach ($column->enumValues as $enumValue) {
                    $dropDownOptions[$enumValue] = Inflector::humanize($enumValue);
                }
                return "\$form->field(\$model, '$attribute')->dropDownList("
                    . preg_replace("/\n\s*/", ' ', VarDumper::export($dropDownOptions)).", ['prompt' => ''])";
            } elseif ($column->phpType !== 'string' || $column->size === null) {
	            $partes = explode('_',$column->name); 
							$finalCampo=$partes[count($partes)-1];
	            if($finalCampo == "did"){			
		            $this->c++;
 					return "\$form->field(\$model, '$attribute')->dropDownList(ArrayHelper::map(app\\models\\".ucfirst($tableSchema->foreignKeys[$this->c][0])."::find()->asArray()->all(), 'id', 'nombre'), ['prompt'=>'-Seleccione-'])";
	            }else if($finalCampo == "aid"){
		            $this->c++;
		            return "\$form->field(\$model, '$attribute')->widget(Select2::classname(), [
							    'data' => ArrayHelper::map(app\\models\\".ucfirst($tableSchema->foreignKeys[$this->c][0])."::find()->asArray()->all(), 'id', 'nombre'),
							    'language' => 'es',
							    'theme' => Select2::THEME_CLASSIC,
							    'options' => ['placeholder' => '-Seleccione-'],
							    'pluginOptions' => [
							        'allowClear' => true
							    ],
								]);";
				}else if($finalCampo == "f"){
					return "\$form->field(\$model, '$attribute')->widget(DateControl::classname(), [
					    'type'=>DateControl::FORMAT_DATE,							    
					]);";								
	            }else if($finalCampo == "ft"){
		          	return "\$form->field(\$model, '$attribute')->widget(DateControl::classname(), [
								    'type'=>DateControl::FORMAT_DATETIME,							    
								]);";
				}else if($finalCampo == "m"){
					return "\$form->field(\$model, '$attribute')->widget(MaskMoney::classname(), [
					    'pluginOptions' => [
					        'prefix' => '$ ',
					        'suffix' => '',
					        'allowNegative' => false
					    ]
					]);";
		          }else{
		            return "\$form->field(\$model, '$attribute')->$input()";
	            }
                
            } else {
                return "\$form->field(\$model, '$attribute')->$input(['maxlength' => true])";
            }
        }
    }
开发者ID:rzamarripa,项目名称:shabel,代码行数:80,代码来源:Generator.php

示例12: getFieldType

 public function getFieldType($params)
 {
     $params = ArrayHelper::merge(['lang' => false, 'bsCol' => false], $params);
     /* @var $attribute string */
     /* @var $model \yii\db\ActiveRecord */
     /* @var $modelStr string */
     /* @var $attributeStr string */
     /* @var $lang bool */
     /* @var $fix bool */
     extract($params);
     $field = "\$form->field(" . $modelStr . ", " . $attributeStr . ")";
     $tableSchema = $model->getTableSchema();
     if ($tableSchema === false || !isset($tableSchema->columns[$attribute])) {
         if (preg_match('/^(password|pass|passwd|passcode)$/i', $attribute)) {
             return $field . "->passwordInput()";
         } else {
             return $field;
         }
     }
     $column = $tableSchema->columns[$attribute];
     if ($lang) {
         $t = "\t\t\t\t\t";
         $t2 = "\t\t\t\t\t";
         $t3 = "\t\t\t\t\t\t";
     } else {
         if ($fix) {
             $t = "\t\t\t\t";
             $t2 = "\t\t\t";
             $t3 = "\t\t\t\t";
         } else {
             $t = "\t\t";
             $t2 = "\t";
             $t3 = "\t\t";
         }
     }
     $column->comment = strtolower($column->comment);
     if ($column->comment == 'redactor') {
         return "\\pavlinter\\adm\\Adm::widget('Redactor',[\n{$t3}'form' => \$form,\n{$t3}'model'      => " . $modelStr . ",\n{$t3}'attribute'  => " . $attributeStr . "\n{$t2}])";
     }
     if ($column->comment == 'fileinput') {
         return "\\pavlinter\\adm\\Adm::widget('FileInput',[\n{$t3}'form'        => \$form,\n{$t3}'model'       => " . $modelStr . ",\n{$t3}'attribute'   => " . $attributeStr . "\n{$t2}])";
     }
     if ($column->comment == 'checkbox') {
         return "\$form->field(" . $modelStr . ", " . $attributeStr . ", [\"template\" => \"{input}\\n{label}\\n{hint}\\n{error}\"])->widget(\\kartik\\checkbox\\CheckboxX::classname(), [\n{$t3}'pluginOptions' => [\n\t{$t3}'threeState' => false\n{$t3}]\n{$t2}]);";
     }
     if ($column->comment == 'select2' || $column->comment == 'range' || $column->dbType === 'tinyint(1)') {
         if ($column->comment == 'range' || $column->dbType === 'tinyint(1)') {
             $data = "\$model::{$column->name}_list()";
         } else {
             $data = '[]';
         }
         return $field . "->widget(\\kartik\\widgets\\Select2::classname(), [\n{$t3}'data' => {$data},\n{$t3}'options' => ['placeholder' => Adm::t('','Select ...', ['dot' => false])],\n{$t3}'pluginOptions' => [\n\t{$t3}'allowClear' => true,\n{$t3}]\n{$t2}]);";
     }
     if ($column->phpType === 'boolean' || $column->phpType === 'tinyint(1)') {
         return $field . "->checkbox()";
     } elseif ($column->type === 'text' || $column->comment == 'textarea') {
         return $field . "->textarea(['rows' => 6])";
     } else {
         if (preg_match('/^(password|pass|passwd|passcode)$/i', $column->name)) {
             $input = 'passwordInput';
         } else {
             $input = 'textInput';
         }
         if (is_array($column->enumValues) && count($column->enumValues) > 0) {
             $dropDownOptions = [];
             foreach ($column->enumValues as $enumValue) {
                 $dropDownOptions[$enumValue] = Inflector::humanize($enumValue);
             }
             return $field . "->dropDownList(" . preg_replace("/\n\\s*/", ' ', VarDumper::export($dropDownOptions)) . ", ['prompt' => ''])";
         } elseif ($column->phpType !== 'string' || $column->size === null) {
             return $field . "->{$input}()";
         } else {
             return $field . "->{$input}(['maxlength' => {$column->size}])";
         }
     }
 }
开发者ID:pavlinter,项目名称:yii2-adm-app,代码行数:76,代码来源:Generator.php

示例13: generateActiveField

 /**
  * Generates code for active field
  * @param string $attribute
  * @return string
  */
 public function generateActiveField($attribute)
 {
     $items_generator = $this->items_generator;
     $tableSchema = $this->getTableSchema();
     if ($tableSchema === false || !isset($tableSchema->columns[$attribute])) {
         if (preg_match('/^(password|pass|passwd|passcode)$/i', $attribute)) {
             return $items_generator::generateField($attribute, null, $this->templateType, 'passwordInput', null);
         } else {
             return $items_generator::generateField($attribute, null, $this->templateType, null, null);
         }
     }
     $column = $tableSchema->columns[$attribute];
     if ($column->phpType === 'boolean') {
         return $items_generator::generateField($attribute, null, $this->templateType, 'checkbox', null);
     } elseif ($column->type === 'text') {
         return $items_generator::generateField($attribute, null, $this->templateType, 'textarea', ['rows' => 6]);
     } else {
         if (preg_match('/^(password|pass|passwd|passcode)$/i', $column->name)) {
             $input = 'passwordInput';
         } else {
             $input = 'textInput';
         }
         if (is_array($column->enumValues) && count($column->enumValues) > 0) {
             $dropDownOptions = [];
             foreach ($column->enumValues as $enumValue) {
                 $dropDownOptions[$enumValue] = Inflector::humanize($enumValue);
             }
             return $items_generator::generateField($attribute, $dropDownOptions, $this->templateType, 'dropDownList', ['prompt' => '']);
         } elseif ($column->phpType !== 'string' || $column->size === null) {
             return $items_generator::generateField($attribute, null, $this->templateType, $input, null);
         } else {
             return $items_generator::generateField($attribute, null, $this->templateType, $input, ['maxlength' => true]);
         }
     }
 }
开发者ID:aayaresko,项目名称:yii2-extended-gii,代码行数:40,代码来源:Generator.php

示例14: generateActiveField

 /**
  * Generates code for active field
  * @param string $attribute
  * @return string
  */
 public function generateActiveField($attribute)
 {
     $tableSchema = $this->getTableSchema();
     if ($tableSchema === false || !isset($tableSchema->columns[$attribute])) {
         if (preg_match('/^(password|pass|passwd|passcode)$/i', $attribute)) {
             return "\$form->field(\$model, '{$attribute}')->passwordInput()";
         } else {
             return "\$form->field(\$model, '{$attribute}')";
         }
     }
     $column = $tableSchema->columns[$attribute];
     if ($column->phpType === 'boolean') {
         return "\$form->field(\$model, '{$attribute}')->checkbox()";
     } elseif ($column->type === 'text') {
         return "\$form->field(\$model, '{$attribute}')->textarea(['rows' => 6])";
     } else {
         if (preg_match('/^(password|pass|passwd|passcode)$/i', $column->name)) {
             $input = 'passwordInput';
         } else {
             $input = 'textInput';
         }
         if (is_array($column->enumValues) && count($column->enumValues) > 0) {
             $dropDownOptions = [];
             foreach ($column->enumValues as $enumValue) {
                 $dropDownOptions[$enumValue] = Inflector::humanize($enumValue);
             }
             return "\$form->field(\$model, '{$attribute}')->dropDownList(" . preg_replace("/\n\\s*/", ' ', VarDumper::export($dropDownOptions)) . ", ['prompt' => ''])";
         } elseif ($column->phpType !== 'string' || $column->size === null) {
             return "\$form->field(\$model, '{$attribute}')->{$input}()";
         } else {
             return "\$form->field(\$model, '{$attribute}')->{$input}(['maxlength' => {$column->size}])";
         }
     }
 }
开发者ID:rocketyang,项目名称:yii2-gii-adminlte,代码行数:39,代码来源:Generator.php

示例15: importStationCommodity

 /**
  * Import station commodities information
  * @param array $station
  * @param string $class
  * @param array $data
  * @return boolean
  */
 private function importStationCommodity($station, $class, $model, $data)
 {
     Yii::$app->db->createCommand('DELETE FROM station_commodities WHERE station_id = :station_id AND type=:type')->bindValue(':station_id', $station['id'])->bindValue(':type', $class)->execute();
     $i = 0;
     foreach ($data as $d) {
         if ($class === 'listings') {
             $commodity = Commodity::find()->where(['id' => $d['commodity_id']])->one();
         } else {
             $commodity = Commodity::find()->where(['name' => $d])->one();
         }
         if ($commodity !== NULL) {
             $model->attributes = ['station_id' => $station['id'], 'commodity_id' => $commodity->id, 'type' => (string) $class, 'supply' => isset($d['supply']) ? $d['supply'] : null, 'buy_price' => isset($d['buy_price']) ? $d['buy_price'] : null, 'sell_price' => isset($d['sell_price']) ? $d['sell_price'] : null, 'demand' => isset($d['demand']) ? $d['demand'] : null];
             if ($model->save()) {
                 $i++;
             }
         } else {
             Yii::warning("{$station['id']}::{$station['name']} - Couldn't find commodity {$commodity}", __METHOD__);
         }
     }
     $inflected = \yii\helpers\Inflector::humanize($class);
     $this->stdOut("    - {$inflected} :: {$i}\n");
 }
开发者ID:charlesportwoodii,项目名称:galnet-api,代码行数:29,代码来源:ImportController.php


注:本文中的yii\helpers\Inflector::humanize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。