Evgeniy Solovyev avatar Evgeniy Solovyev committed 085f2d5

Added file field generation (for image-like field names). Need to fix: 1) 2+ image (upload) fields generation; 2) valid attribute label generation using array-notation (e. g. "photo[]", for html5 multiupload possibility).

Comments (0)

Files changed (1)

generators/AweCrud/AweCrudCode.php

             return "\$form->dropDownListRow(\$model, '{$column->name}', CHtml::listData({$relatedModelClass}::model()->findAll(), '{$foreignPk}', {$relatedModelClass}::representingColumn()){$prompt})";
         }
 
-        if (strtoupper($column->dbType) == 'TINYINT(1)'
+        if($column->name == $this->hasUpload()) {
+            return "\$form->fileFieldRow(\$model, '{$column->name}[]', array('multiple' => 'multiple'))";
+        } elseif (strtoupper($column->dbType) == 'TINYINT(1)'
             || strtoupper($column->dbType) == 'BIT'
             || strtoupper($column->dbType) == 'BOOL'
             || strtoupper($column->dbType) == 'BOOLEAN'
         return $controller;
     }
 
+    public function hasUpload()
+    {
+        foreach($this->tableSchema->columns as $column)
+        {
+            if (in_array($column->name, $this->imageFields))
+            {
+                return $column->name;
+                break;
+            }
+        }
+
+        return false;
+    }
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.