src/commands/CrudController.php
public function generateModelContent($fileNamepsace, $className, $apiEndpoint, TableSchema $schema, $i18nFields)
    {
        $alias = Inflector::humanize(Inflector::camel2words($className));
        $dbTableName = $schema->fullName;
        
        $fields = [];
        $textfields = [];
        $properties = [];
        $ngrestFieldConfig = [];
        foreach ($schema->columns as $k => $v) {
            $properties[$v->name] = $v->type;
            if ($v->isPrimaryKey) {
                continue;
            }
            $fields[] = $v->name;
            
            if ($v->phpType == 'string') {
                $textfields[] = $v->name;
            }
            
            if ($v->type == 'text') {
                $ngrestFieldConfig[$v->name] = 'textarea';
            }
            if ($v->type == 'string') {
                $ngrestFieldConfig[$v->name] = 'text';
            }
            if ($v->type == 'integer' || $v->type == 'bigint' || $v->type == 'smallint' || $v->type == 'tinyint') {
                $ngrestFieldConfig[$v->name] = 'number';
            }
            if ($v->type == 'decimal' || $v->type == 'float' || $v->type == 'double') {
                $ngrestFieldConfig[$v->name] = 'decimal';
            }
            if ($v->type == 'boolean') {
                $ngrestFieldConfig[$v->name] = 'toggleStatus';
            }
        };
        
        return $this->view->render('@admin/commands/views/crud/create_model.php', [
            'namespace' => $fileNamepsace,
            'className' => $className,
            'luyaVersion' => $this->getGeneratorText('crud/create'),
            'apiEndpoint' => $apiEndpoint,
            'dbTableName' => $dbTableName,
            'fields' => $fields,
            'textFields' => $textfields,
            'rules' => $this->generateRules($schema),
            'labels' => $this->generateLabels($schema),
            'properties' => $properties,
            'ngrestFieldConfig' => $ngrestFieldConfig,
            'i18nFields' => $i18nFields,
            'alias' => $alias,
        ]);
    }
public function generateModelContent($fileNamepsace, $className, $apiEndpoint, TableSchema $schema, $i18nFields)
    {
        $alias = Inflector::humanize(Inflector::camel2words($className));
        $dbTableName = $schema->fullName;
        
        $fields = [];
        $textfields = [];
        $properties = [];
        $ngrestFieldConfig = [];
        foreach ($schema->columns as $k => $v) {
            $properties[$v->name] = $v->type;
            if ($v->isPrimaryKey) {
                continue;
            }
            $fields[] = $v->name;
            
            if ($v->phpType == 'string') {
                $textfields[] = $v->name;
            }
            
            if ($v->type == 'text') {
                $ngrestFieldConfig[$v->name] = 'textarea';
            }
            if ($v->type == 'string') {
                $ngrestFieldConfig[$v->name] = 'text';
            }
            if ($v->type == 'integer' || $v->type == 'bigint' || $v->type == 'smallint' || $v->type == 'tinyint') {
                $ngrestFieldConfig[$v->name] = 'number';
            }
            if ($v->type == 'decimal' || $v->type == 'float' || $v->type == 'double') {
                $ngrestFieldConfig[$v->name] = 'decimal';
            }
            if ($v->type == 'boolean') {
                $ngrestFieldConfig[$v->name] = 'toggleStatus';
            }
        };
        
        return $this->view->render('@admin/commands/views/crud/create_model.php', [
            'namespace' => $fileNamepsace,
            'className' => $className,
            'luyaVersion' => $this->getGeneratorText('crud/create'),
            'apiEndpoint' => $apiEndpoint,
            'dbTableName' => $dbTableName,
            'fields' => $fields,
            'textFields' => $textfields,
            'rules' => $this->generateRules($schema),
            'labels' => $this->generateLabels($schema),
            'properties' => $properties,
            'ngrestFieldConfig' => $ngrestFieldConfig,
            'i18nFields' => $i18nFields,
            'alias' => $alias,
        ]);
    }
public function generateModelContent ( $ fileNamepsace , $ className , $ apiEndpoint , TableSchema $ schema , $ i18nFields ) { $ alias = Inflector :: humanize ( Inflector :: camel2words ( $ className ) ) ; $ dbTableName = $ schema -> fullName ; $ fields = [ ] ; $ textfields = [ ] ; $ properties = [ ] ; $ ngrestFieldConfig = [ ] ; foreach ( $ schema -> columns as $ k => $ v ) { $ properties [ $ v -> name ] = $ v -> type ; if ( $ v -> isPrimaryKey ) { continue ; } $ fields [ ] = $ v -> name ; if ( $ v -> phpType == 'string' ) { $ textfields [ ] = $ v -> name ; } if ( $ v -> type == 'text' ) { $ ngrestFieldConfig [ $ v -> name ] = 'textarea' ; } if ( $ v -> type == 'string' ) { $ ngrestFieldConfig [ $ v -> name ] = 'text' ; } if ( $ v -> type == 'integer' || $ v -> type == 'bigint' || $ v -> type == 'smallint' || $ v -> type == 'tinyint' ) { $ ngrestFieldConfig [ $ v -> name ] = 'number' ; } if ( $ v -> type == 'decimal' || $ v -> type == 'float' || $ v -> type == 'double' ) { $ ngrestFieldConfig [ $ v -> name ] = 'decimal' ; } if ( $ v -> type == 'boolean' ) { $ ngrestFieldConfig [ $ v -> name ] = 'toggleStatus' ; } } ; return $ this -> view -> render ( '@admin/commands/views/crud/create_model.php' , [ 'namespace' => $ fileNamepsace , 'className' => $ className , 'luyaVersion' => $ this -> getGeneratorText ( 'crud/create' ) , 'apiEndpoint' => $ apiEndpoint , 'dbTableName' => $ dbTableName , 'fields' => $ fields , 'textFields' => $ textfields , 'rules' => $ this -> generateRules ( $ schema ) , 'labels' => $ this -> generateLabels ( $ schema ) , 'properties' => $ properties , 'ngrestFieldConfig' => $ ngrestFieldConfig , 'i18nFields' => $ i18nFields , 'alias' => $ alias , ] ) ; }
Generate the model content based on its view file.

@param string $fileNamepsace
@param string $className
@param string $apiEndpoint
@param \yii\db\TableSchema $schema
@param boolean $i18nFields
@return string
Generate the model content based on its view file .