Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
test-project
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Junaid Rahman pv
test-project
Commits
16402987
Commit
16402987
authored
Sep 22, 2016
by
Junaid Rahman pv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
theme module: added file upload option
parent
1adbe559
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
50 deletions
+68
-50
ThemeController.php
backend/modules/theme/controllers/ThemeController.php
+0
-1
ThemeFileController.php
backend/modules/theme/controllers/ThemeFileController.php
+16
-19
_form.php
backend/modules/theme/views/theme-file/_form.php
+2
-10
upload.php
backend/modules/theme/views/theme-file/upload.php
+28
-10
m160830_105840_category.php
common/migrations/db/m160830_105840_category.php
+1
-1
m160903_101233_theme.php
common/migrations/db/m160903_101233_theme.php
+5
-5
ThemeFiles.php
common/models/ThemeFiles.php
+16
-4
No files found.
backend/modules/theme/controllers/ThemeController.php
View file @
16402987
...
...
@@ -138,7 +138,6 @@ class ThemeController extends Controller
$modelFiles
=
$model
->
themeFiles
;
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
()))
{
//&& $model->save()
$oldIDs
=
ArrayHelper
::
map
(
$modelFiles
,
'id'
,
'id'
);
$modelFiles
=
Model
::
createMultiple
(
ThemeFiles
::
classname
(),
$modelFiles
);
Model
::
loadMultiple
(
$modelFiles
,
Yii
::
$app
->
request
->
post
());
...
...
backend/modules/theme/controllers/ThemeFileController.php
View file @
16402987
...
...
@@ -2,6 +2,7 @@
namespace
backend\modules\theme\controllers
;
use
common\models\ThemeFiles
;
use
yii
;
use
common\models\Theme
;
use
yii\web\NotFoundHttpException
;
...
...
@@ -23,42 +24,38 @@ class ThemeFileController extends \yii\web\Controller
*/
protected
function
findModel
(
$id
)
{
if
((
$model
=
Theme
::
findOne
(
$id
))
!==
null
)
{
if
((
$model
=
Theme
Files
::
findOne
(
$id
))
!==
null
)
{
return
$model
;
}
else
{
throw
new
NotFoundHttpException
(
'The requested page does not exist.'
);
}
}
public
function
actionUpload
(
$id
){
$model
=
$this
->
findModel
(
$id
);
$modelFiles
=
$model
->
themeFiles
;
public
function
actionUpload
()
{
$model
=
new
ThemeFiles
();
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
()))
{
//&& $model->save()
// get the uploaded file instance. for multiple file uploads
// the following data will return an array
$theme_file
=
UploadedFile
::
getInstance
(
$model
,
'
theme-
file'
);
$theme_file
=
UploadedFile
::
getInstance
(
$model
,
'file'
);
// the path to save file, you can set an uploadPath
$path
=
$model
->
file
;
if
(
$path
)
{
echo
'a'
;
if
(
$model
->
save
())
{
$theme_file
->
saveAs
(
$path
);
return
$this
->
redirect
([
'view'
,
'id'
=>
$model
->
id
]);
}
else
{
// error in saving model
// the path to save file,
$folderPath
=
yii
::
getAlias
(
'@storage/private/theme-assets/'
)
.
$model
->
theme_code
;
if
(
!
is_dir
(
$folderPath
))
{
mkdir
(
$folderPath
);
}
$path
=
$folderPath
.
'/'
.
$model
->
file_code
;
if
(
$model
->
save
(
false
))
{
$theme_file
->
saveAs
(
$path
);
}
else
{
echo
'aaa'
;
echo
$theme_file
->
id
;
echo
'Error'
;
exit
();
}
}
return
$this
->
render
(
'upload'
);
return
$this
->
redirect
([
'theme/index'
]);
}
}
backend/modules/theme/views/theme-file/_form.php
View file @
16402987
...
...
@@ -12,8 +12,6 @@ use yii\helpers\Url;
<div
class=
"customer-form"
>
<?php
$form
=
ActiveForm
::
begin
([
'options'
=>
[
'enctype'
=>
'multipart/form-data'
],
'id'
=>
'dynamic-form'
]);
?>
<div
class=
"panel panel-default"
>
<div
class=
"panel-body"
>
<table>
...
...
@@ -56,11 +54,10 @@ use yii\helpers\Url;
?>
<div
id=
'modalContent'
.
<?=
$value
[
'id'
]
?>
style=
"
align-content
: center"
>
<div
id=
'modalContent'
.
<?=
$value
[
'id'
]
?>
style=
"
text-align
: center"
>
<?=
$this
->
render
(
'upload'
,
[
'model'
=>
$model
,
'modelFiles'
=>
$modelFiles
,
'model'
=>
$modelFiles
[
0
],
])
?>
</div>
...
...
@@ -84,10 +81,5 @@ use yii\helpers\Url;
</div>
</div>
<div
class=
"form-group"
>
<?=
Html
::
submitButton
(
'Save'
,
[
'class'
=>
'btn btn-primary'
])
?>
</div>
<?php
ActiveForm
::
end
();
?>
</div>
backend/modules/theme/views/theme-file/upload.php
View file @
16402987
...
...
@@ -6,30 +6,47 @@
* Time: 01:15 PM
*/
/* @var $model
Files
common\models\ThemeFiles */
/* @var $model common\models\ThemeFiles */
use
yii\widgets\ActiveForm
;
use
yii\bootstrap\Html
;
?>
<?php
$form
=
ActiveForm
::
begin
();
?>
<?php
$form
=
ActiveForm
::
begin
([
'options'
=>
[
'enctype'
=>
'multipart/form-data'
],
'id'
=>
'dynamic-form'
,
'action'
=>
'../theme-file/upload'
]);
?>
<div
class=
"conatiner"
>
<div
id=
"myTabContent"
class=
"tab-content"
>
<div
class=
"row"
>
<div
class=
"col-md-6"
>
<p>
Choose your file to upload
</p>
<div
class=
"col-md-11"
>
<?=
$form
->
field
(
$model
,
'file'
)
->
fileInput
([
'class'
=>
'btn btn-default'
])
?>
</div>
<div
class=
"col-md-11"
>
<?=
$form
->
field
(
$model
,
'file_code'
)
->
hiddenInput
([
'value'
=>
$model
->
file_code
])
->
label
(
false
)
?>
</div>
<div
class=
"row
"
>
<div
class=
"col-md-6"
>
<?=
$form
->
field
(
$modelFiles
[
0
],
'file'
)
->
fileInput
([
'class'
=>
'btn btn-primary'
]
)
?>
<?=
$modelFiles
[
0
]
->
file_code
?>
<div
class=
"col-md-11
"
>
<?=
$form
->
field
(
$model
,
'theme_code'
)
->
hiddenInput
([
'value'
=>
$model
->
theme_code
])
->
label
(
false
)
?>
</div>
</div>
<div
class=
"form-group"
>
<?=
Html
::
submitButton
()
?>
<?=
Html
::
submitButton
(
Yii
::
t
(
'backend'
,
'Upload'
),
[
'class'
=>
'btn btn-primary'
])
?>
</div>
</div>
<?php
ActiveForm
::
end
();
?>
\ No newline at end of file
common/migrations/db/m160830_105840_category.php
View file @
16402987
...
...
@@ -27,7 +27,7 @@ class m160830_105840_category extends Migration
$this
->
createTable
(
'{{%category_files}}'
,
[
'id'
=>
$this
->
primaryKey
(),
'category_id'
=>
$this
->
integer
()
->
notNull
(),
'code'
=>
$this
->
string
(
32
)
->
notNull
(),
'code'
=>
$this
->
string
(
11
)
->
notNull
(),
'type'
=>
$this
->
integer
()
->
notNull
(),
'name'
=>
$this
->
string
(
32
)
->
notNull
(),
'created_at'
=>
$this
->
integer
(),
...
...
common/migrations/db/m160903_101233_theme.php
View file @
16402987
...
...
@@ -15,7 +15,7 @@ class m160903_101233_theme extends Migration
$this
->
createTable
(
'{{%theme}}'
,
[
'id'
=>
$this
->
primaryKey
(),
'category_id'
=>
$this
->
integer
()
->
notNull
(),
'code'
=>
$this
->
string
(
32
)
->
notNull
(),
'code'
=>
$this
->
string
(
11
)
->
notNull
(),
'slug'
=>
$this
->
string
(
32
)
->
notNull
(),
'name'
=>
$this
->
string
(
32
)
->
notNull
(),
'description'
=>
$this
->
string
(
512
),
...
...
@@ -26,16 +26,16 @@ class m160903_101233_theme extends Migration
$this
->
createTable
(
'{{%theme_files}}'
,
[
'id'
=>
$this
->
primaryKey
(),
'theme_code'
=>
$this
->
integer
(
)
->
notNull
(),
'file_code'
=>
$this
->
integer
(
)
->
notNull
(),
'theme_code'
=>
$this
->
string
(
11
)
->
notNull
(),
'file_code'
=>
$this
->
string
(
11
)
->
notNull
(),
'created_at'
=>
$this
->
integer
(),
'updated_at'
=>
$this
->
integer
()
],
$tableOptions
);
$this
->
addForeignKey
(
'fk_theme_category'
,
'{{%theme}}'
,
'category_id'
,
'{{%category}}'
,
'id'
,
'cascade'
,
'cascade'
);
$this
->
addForeignKey
(
'fk_theme_files_theme'
,
'{{%theme_files}}'
,
'theme_code'
,
'{{%theme}}'
,
'
id
'
,
'cascade'
,
'cascade'
);
$this
->
addForeignKey
(
'fk_theme_category_files'
,
'{{%theme_files}}'
,
'file_code'
,
'{{%category_files}}'
,
'
id
'
,
'cascade'
,
'cascade'
);
$this
->
addForeignKey
(
'fk_theme_files_theme'
,
'{{%theme_files}}'
,
'theme_code'
,
'{{%theme}}'
,
'
code
'
,
'cascade'
,
'cascade'
);
$this
->
addForeignKey
(
'fk_theme_category_files'
,
'{{%theme_files}}'
,
'file_code'
,
'{{%category_files}}'
,
'
code
'
,
'cascade'
,
'cascade'
);
}
public
function
safeDown
()
...
...
common/models/ThemeFiles.php
View file @
16402987
...
...
@@ -3,6 +3,7 @@
namespace
common\models
;
use
Yii
;
use
yii\behaviors\TimestampBehavior
;
/**
* This is the model class for table "{{%theme_files}}".
...
...
@@ -33,15 +34,25 @@ class ThemeFiles extends \yii\db\ActiveRecord
return
'{{%theme_files}}'
;
}
public
function
behaviors
()
{
return
[
[
'class'
=>
TimestampBehavior
::
className
(),
'createdAtAttribute'
=>
'created_at'
,
'updatedAtAttribute'
=>
'updated_at'
]
];
}
/**
* @inheritdoc
*/
public
function
rules
()
{
return
[
[[
'theme_code'
,
'file_code'
],
'required'
],
[[
'theme_code'
,
'file_code'
,
'created_at'
,
'updated_at'
],
'integer
'
],
[[
'
base_url'
,
'base_path'
],
'string'
,
'max'
=>
1024
],
[[
'theme_code'
,
'file_code'
,
'file'
],
'required'
],
[[
'theme_code'
,
'file_code'
],
'string
'
],
[[
'
created_at'
,
'updated_at'
],
'integer'
],
[[
'file_code'
],
'exist'
,
'skipOnError'
=>
true
,
'targetClass'
=>
CategoryFiles
::
className
(),
'targetAttribute'
=>
[
'file_code'
=>
'id'
]],
[[
'theme_code'
],
'exist'
,
'skipOnError'
=>
true
,
'targetClass'
=>
Theme
::
className
(),
'targetAttribute'
=>
[
'theme_code'
=>
'id'
]],
[[
'file'
],
'file'
],
...
...
@@ -61,6 +72,7 @@ class ThemeFiles extends \yii\db\ActiveRecord
'base_path'
=>
Yii
::
t
(
'common'
,
'Base Path'
),
'created_at'
=>
Yii
::
t
(
'common'
,
'Created At'
),
'updated_at'
=>
Yii
::
t
(
'common'
,
'Updated At'
),
'file'
=>
Yii
::
t
(
'common'
,
'Choose your file to upload'
)
];
}
...
...
@@ -80,7 +92,7 @@ class ThemeFiles extends \yii\db\ActiveRecord
return
$this
->
hasOne
(
Theme
::
className
(),
[
'id'
=>
'theme_code'
]);
}
public
function
getFilePath
(
$theme_code
,
$file_code
)
public
static
function
getFilePath
(
$theme_code
,
$file_code
)
{
return
yii
::
getAlias
(
'@storage/private/theme-assets/'
)
.
$theme_code
.
'/'
.
$file_code
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment