schmunk42\giiant\helpers\SaveForm::getFormAttributesValues PHP Method

getFormAttributesValues() public static method

get form attributes values.
public static getFormAttributesValues ( $generator, $attributes )
    public static function getFormAttributesValues($generator, $attributes)
    {
        $values = [];
        foreach ($attributes as $name) {
            $values[strtolower($name)] = ['value' => $generator->{$name}, 'name' => $name];
        }
        return $values;
    }

Usage Example

Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function generate()
 {
     $files = [];
     $relations = $this->generateRelations();
     $db = $this->getDbConnection();
     foreach ($this->getTableNames() as $tableName) {
         list($relations, $translations) = array_values($this->extractTranslations($tableName, $relations));
         //var_dump($relations,$tableName);exit;
         $className = php_sapi_name() === 'cli' ? $this->generateClassName($tableName) : $this->modelClass;
         $queryClassName = $this->generateQuery ? $this->generateQueryClassName($className) : false;
         $tableSchema = $db->getTableSchema($tableName);
         $params = ['tableName' => $tableName, 'className' => $className, 'queryClassName' => $queryClassName, 'tableSchema' => $tableSchema, 'labels' => $this->generateLabels($tableSchema), 'hints' => $this->generateHints($tableSchema), 'rules' => $this->generateRules($tableSchema), 'relations' => isset($relations[$tableName]) ? $relations[$tableName] : [], 'ns' => $this->ns, 'enum' => $this->getEnum($tableSchema->columns)];
         if (!empty($translations)) {
             $params['translation'] = $translations;
         }
         $params['blameable'] = $this->generateBlameable($tableSchema);
         $params['timestamp'] = $this->generateTimestamp($tableSchema);
         $files[] = new CodeFile(Yii::getAlias('@' . str_replace('\\', '/', $this->ns)) . '/base/' . $className . $this->baseClassSuffix . '.php', $this->render('model.php', $params));
         $modelClassFile = Yii::getAlias('@' . str_replace('\\', '/', $this->ns)) . '/' . $className . '.php';
         if ($this->generateModelClass || !is_file($modelClassFile)) {
             $files[] = new CodeFile($modelClassFile, $this->render('model-extended.php', $params));
         }
         if ($queryClassName) {
             $queryClassFile = Yii::getAlias('@' . str_replace('\\', '/', $this->queryNs)) . '/' . $queryClassName . '.php';
             if ($this->generateModelClass || !is_file($queryClassFile)) {
                 $params = ['className' => $queryClassName, 'modelClassName' => $className];
                 $files[] = new CodeFile($queryClassFile, $this->render('query.php', $params));
             }
         }
         /*
          * create gii/[name]GiiantModel.json with actual form data
          */
         $suffix = str_replace(' ', '', $this->getName());
         $formDataDir = Yii::getAlias('@' . str_replace('\\', '/', $this->ns));
         $formDataFile = StringHelper::dirname($formDataDir) . '/gii' . '/' . $tableName . $suffix . '.json';
         $formData = json_encode(SaveForm::getFormAttributesValues($this, $this->formAttributes()));
         $files[] = new CodeFile($formDataFile, $formData);
     }
     return $files;
 }
All Usage Examples Of schmunk42\giiant\helpers\SaveForm::getFormAttributesValues