public function testCRUDGenerator() { $generator = new CRUDGenerator(); $generator->template = 'default'; $generator->modelClass = 'yiiunit\\extensions\\gii\\Profile'; $generator->controllerClass = 'app\\TestController'; $valid = $generator->validate(); $this->assertTrue($valid, 'Validation failed: ' . print_r($generator->getErrors(), true)); $this->assertNotEmpty($generator->generate()); }
/** * @inheritdoc */ public function hints() { return array_merge(parent::hints(), ['controllerID' => 'Controller ID should be in lower case and may contain module ID(s) separated by slashes. For example: <ul> <li><code>order</code> generates <code>OrderController.php</code></li> <li><code>order-item</code> generates <code>OrderItemController.php</code></li> <li><code>admin/user</code> generates <code>UserController.php</code> under <code>admin</code> directory.</li> </ul>']); }
/** * Generates code for active field by using the provider queue * * @param ColumnSchema $column * @param null $model * * @return mixed|string */ public function activeField($attribute, $model = null) { if ($model === null) { $model = $this->modelClass; } $code = $this->callProviderQueue(__FUNCTION__, $attribute, $model, $this); if ($code !== null) { Yii::trace("found provider for '{$attribute}'", __METHOD__); return $code; } else { $column = $this->getColumnByAttribute($attribute); if (!$column) { return null; } else { return parent::generateActiveField($attribute); } } }
public function validateClass($attribute, $params) { if ($this->singularEntities) { $this->{$attribute} = Inflector::singularize($this->{$attribute}); } parent::validateClass($attribute, $params); }
/** * @inheritdoc */ public function stickyAttributes() { return array_merge(parent::stickyAttributes(), ['baseControllerClass', 'moduleID', 'indexWidgetType', 'tPrefix', 'defaultLanguage', 'layout', 'addBootstrapPanel']); }
public function generateActiveField($attribute) { $tableSchema = $this->getTableSchema(); if ($tableSchema === false || !isset($tableSchema->columns[$attribute])) { return parent::generateActiveField($attribute); } $column = $tableSchema->columns[$attribute]; if ($this->isBoolean($column)) { return "\$form->field(\$model, '{$attribute}')->checkbox()"; } return parent::generateActiveField($attribute); }
/** * Generates code for active field by using the provider queue * * @param string $attribute * * @return string */ public function activeField(ColumnSchema $column, $model = null) { Yii::trace("Rendering activeField for '{$column->name}'", __METHOD__); if ($model === null) { $model = $this->modelClass; } $code = $this->callProviderQueue(__FUNCTION__, $column, $model); if ($code !== null) { return $code; } else { return parent::generateActiveField($column->name); } }
/** * @inheritdoc */ public function stickyAttributes() { return array_merge(parent::stickyAttributes(), ['baseControllerClass', 'moduleID', 'indexWidgetType']); }
public function rules() { return ArrayHelper::merge(parent::rules(), [[['columns'], MultipleModelValidator::className(), 'baseModel' => WidgetsCrud::className(), 'skipOnEmpty' => true], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'filter', 'filter' => 'trim'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'required'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.']]); }
/** * @inheritdoc */ public function generateColumnFormat($column) { if (stripos($column->name, 'published') !== false) { return 'boolean'; } elseif (stripos($column->name, 'file') !== false) { return 'file'; } elseif ($column->phpType === 'boolean' || $column->type === Schema::TYPE_SMALLINT && $column->size === 1) { return 'boolean'; } elseif (stripos($column->name, 'link') !== false) { return 'url'; } return parent::generateColumnFormat($column); }
public function generateUrlParams() { $urlParams = parent::generateUrlParams(); $class = $this->modelClass; $modelVariable = $this->variablize($class); $urlParams = str_replace('$model', "\${$modelVariable}", $urlParams); return $urlParams; }
/** * @inheritdoc */ public function getNameAttribute() { foreach ($this->getColumnNames() as $name) { if (!strcasecmp($name, 'username') || !strcasecmp($name, 'email')) { return $name; } } return parent::getNameAttribute(); }
/** * @inheritdoc */ public function hints() { return array_merge(parent::hints(), ['searchModelClass' => 'This is the name of the search model class to be generated. You should provide a fully qualified namespaced class name, e.g., <code>backend\\models\\search\\Post</code>.', 'viewModelClass' => 'This is the name of the view model class to be generated. You should provide a fully qualified namespaced class name, e.g., <code>backend\\models\\view\\Post</code>.']); }
public function testCRUDGenerator() { $generator = new CRUDGenerator(); $generator->template = 'default'; $generator->modelClass = 'yiiunit\\extensions\\gii\\Profile'; $generator->controllerClass = 'app\\TestController'; if ($generator->validate()) { $generator->generate(); } else { print_r($generator->getErrors()); } }
/** * (non-PHPdoc) * @see \yii\gii\generators\crud\Generator::generateActiveField($attribute) */ public function generateActiveField($attribute) { return str_replace(' => ', '=>', parent::generateActiveField($attribute)); }
public function hints() { return array_merge(parent::hints(), ['controllerName' => '用于生成控制器的名称<code>(* ̄(エ) ̄)</code>']); }
/** * @inheritdoc */ public function generate() { $this->getModelAttributes(); return; //$this->readModel($this->modelClass); $this->relationsFields(); $files = parent::generate(); if ($this->enableI18N && $this->addingI18NStrings && !empty($this->I18NStrings)) { if (($pos = strpos($this->controllerClass, '\\controllers\\')) !== false) { $path = rtrim(Yii::getAlias('@' . str_replace('\\', '/', ltrim(substr($this->controllerClass, 0, $pos), '\\'))), '/') . '/messages'; if (is_dir($path)) { foreach (array_diff(scandir($path), ['.', '..']) as $language) { $filename = "{$path}/{$language}/{$this->messageCategory}.php"; $messages = file_exists($filename) ? require $filename : []; $messages = array_merge($messages, array_diff_key($this->I18NStrings, $messages)); $files[] = new CodeFile($filename, "<?php\nreturn " . VarDumper::export($messages) . ";"); } } } } return $files; }