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
4548d620
Commit
4548d620
authored
Aug 31, 2016
by
dianc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Category CRUD
parent
17a7367f
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
424 additions
and
23 deletions
+424
-23
web.php
backend/config/web.php
+26
-23
CategoryController.php
backend/modules/theme/controllers/CategoryController.php
+121
-0
CategorySearch.php
backend/modules/theme/models/search/CategorySearch.php
+69
-0
_form.php
backend/modules/theme/views/category/_form.php
+39
-0
_search.php
backend/modules/theme/views/category/_search.php
+43
-0
create.php
backend/modules/theme/views/category/create.php
+21
-0
index.php
backend/modules/theme/views/category/index.php
+43
-0
update.php
backend/modules/theme/views/category/update.php
+21
-0
view.php
backend/modules/theme/views/category/view.php
+41
-0
No files found.
backend/config/web.php
View file @
4548d620
<?php
$config
=
[
'homeUrl'
=>
Yii
::
getAlias
(
'@backendUrl'
),
'homeUrl'
=>
Yii
::
getAlias
(
'@backendUrl'
),
'controllerNamespace'
=>
'backend\controllers'
,
'defaultRoute'
=>
'timeline-event/index'
,
'controllerMap'
=>
[
'defaultRoute'
=>
'timeline-event/index'
,
'controllerMap'
=>
[
'file-manager-elfinder'
=>
[
'class'
=>
'mihaildev\elfinder\Controller'
,
'access'
=>
[
'manager'
],
...
...
@@ -18,7 +18,7 @@ $config = [
]
]
],
'components'
=>
[
'components'
=>
[
'errorHandler'
=>
[
'errorAction'
=>
'site/error'
,
],
...
...
@@ -26,52 +26,55 @@ $config = [
'cookieValidationKey'
=>
env
(
'BACKEND_COOKIE_VALIDATION_KEY'
)
],
'user'
=>
[
'class'
=>
'yii\web\User'
,
'class'
=>
'yii\web\User'
,
'identityClass'
=>
'common\models\User'
,
'loginUrl'
=>
[
'sign-in/login'
],
'loginUrl'
=>
[
'sign-in/login'
],
'enableAutoLogin'
=>
true
,
'as afterLogin'
=>
'common\behaviors\LoginTimestampBehavior'
],
],
'modules'
=>
[
'modules'
=>
[
'i18n'
=>
[
'class'
=>
'backend\modules\i18n\Module'
,
'defaultRoute'
=>
'i18n-message/index'
'defaultRoute'
=>
'i18n-message/index'
],
'theme'
=>
[
'class'
=>
'backend\modules\theme\Module'
,
]
],
'as globalAccess'
=>
[
'class'
=>
'\common\behaviors\GlobalAccessBehavior'
,
'rules'
=>
[
'as globalAccess'
=>
[
'class'
=>
'\common\behaviors\GlobalAccessBehavior'
,
'rules'
=>
[
[
'controllers'
=>
[
'sign-in'
],
'controllers'
=>
[
'sign-in'
],
'allow'
=>
true
,
'roles'
=>
[
'?'
],
'actions'
=>
[
'login'
]
'actions'
=>
[
'login'
]
],
[
'controllers'
=>
[
'sign-in'
],
'controllers'
=>
[
'sign-in'
],
'allow'
=>
true
,
'roles'
=>
[
'@'
],
'actions'
=>
[
'logout'
]
'actions'
=>
[
'logout'
]
],
[
'controllers'
=>
[
'site'
],
'controllers'
=>
[
'site'
],
'allow'
=>
true
,
'roles'
=>
[
'?'
,
'@'
],
'actions'
=>
[
'error'
]
'actions'
=>
[
'error'
]
],
[
'controllers'
=>
[
'debug/default'
],
'controllers'
=>
[
'debug/default'
],
'allow'
=>
true
,
'roles'
=>
[
'?'
],
],
[
'controllers'
=>
[
'user'
],
'controllers'
=>
[
'user'
],
'allow'
=>
true
,
'roles'
=>
[
'administrator'
],
],
[
'controllers'
=>
[
'user'
],
'controllers'
=>
[
'user'
],
'allow'
=>
false
,
],
[
...
...
@@ -84,11 +87,11 @@ $config = [
if
(
YII_ENV_DEV
)
{
$config
[
'modules'
][
'gii'
]
=
[
'class'
=>
'yii\gii\Module'
,
'class'
=>
'yii\gii\Module'
,
'generators'
=>
[
'crud'
=>
[
'class'
=>
'yii\gii\generators\crud\Generator'
,
'templates'
=>
[
'class'
=>
'yii\gii\generators\crud\Generator'
,
'templates'
=>
[
'yii2-starter-kit'
=>
Yii
::
getAlias
(
'@backend/views/_gii/templates'
)
],
'template'
=>
'yii2-starter-kit'
,
...
...
backend/modules/theme/controllers/CategoryController.php
0 → 100644
View file @
4548d620
<?php
namespace
backend\modules\theme\controllers
;
use
Yii
;
use
common\models\Category
;
use
backend\modules\theme\models\search\CategorySearch
;
use
yii\web\Controller
;
use
yii\web\NotFoundHttpException
;
use
yii\filters\VerbFilter
;
/**
* CategoryController implements the CRUD actions for Category model.
*/
class
CategoryController
extends
Controller
{
public
function
behaviors
()
{
return
[
'verbs'
=>
[
'class'
=>
VerbFilter
::
className
(),
'actions'
=>
[
'delete'
=>
[
'post'
],
],
],
];
}
/**
* Lists all Category models.
* @return mixed
*/
public
function
actionIndex
()
{
$searchModel
=
new
CategorySearch
();
$dataProvider
=
$searchModel
->
search
(
Yii
::
$app
->
request
->
queryParams
);
return
$this
->
render
(
'index'
,
[
'searchModel'
=>
$searchModel
,
'dataProvider'
=>
$dataProvider
,
]);
}
/**
* Displays a single Category model.
* @param integer $id
* @return mixed
*/
public
function
actionView
(
$id
)
{
return
$this
->
render
(
'view'
,
[
'model'
=>
$this
->
findModel
(
$id
),
]);
}
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public
function
actionCreate
()
{
$model
=
new
Category
();
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
())
&&
$model
->
save
())
{
return
$this
->
redirect
([
'view'
,
'id'
=>
$model
->
id
]);
}
else
{
return
$this
->
render
(
'create'
,
[
'model'
=>
$model
,
]);
}
}
/**
* Updates an existing Category model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public
function
actionUpdate
(
$id
)
{
$model
=
$this
->
findModel
(
$id
);
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
())
&&
$model
->
save
())
{
return
$this
->
redirect
([
'view'
,
'id'
=>
$model
->
id
]);
}
else
{
return
$this
->
render
(
'update'
,
[
'model'
=>
$model
,
]);
}
}
/**
* Deletes an existing Category model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public
function
actionDelete
(
$id
)
{
$this
->
findModel
(
$id
)
->
delete
();
return
$this
->
redirect
([
'index'
]);
}
/**
* Finds the Category model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Category the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected
function
findModel
(
$id
)
{
if
((
$model
=
Category
::
findOne
(
$id
))
!==
null
)
{
return
$model
;
}
else
{
throw
new
NotFoundHttpException
(
'The requested page does not exist.'
);
}
}
}
backend/modules/theme/models/search/CategorySearch.php
0 → 100644
View file @
4548d620
<?php
namespace
backend\modules\theme\models\search
;
use
Yii
;
use
yii\base\Model
;
use
yii\data\ActiveDataProvider
;
use
common\models\Category
;
/**
* CategorySearch represents the model behind the search form about `common\models\Category`.
*/
class
CategorySearch
extends
Category
{
/**
* @inheritdoc
*/
public
function
rules
()
{
return
[
[[
'id'
,
'status'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'name'
,
'slug'
,
'description'
,
'image_url'
,
'image_path'
],
'safe'
],
];
}
/**
* @inheritdoc
*/
public
function
scenarios
()
{
// bypass scenarios() implementation in the parent class
return
Model
::
scenarios
();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public
function
search
(
$params
)
{
$query
=
Category
::
find
();
$dataProvider
=
new
ActiveDataProvider
([
'query'
=>
$query
,
]);
if
(
!
(
$this
->
load
(
$params
)
&&
$this
->
validate
()))
{
return
$dataProvider
;
}
$query
->
andFilterWhere
([
'id'
=>
$this
->
id
,
'status'
=>
$this
->
status
,
'created_at'
=>
$this
->
created_at
,
'updated_at'
=>
$this
->
updated_at
,
]);
$query
->
andFilterWhere
([
'like'
,
'name'
,
$this
->
name
])
->
andFilterWhere
([
'like'
,
'slug'
,
$this
->
slug
])
->
andFilterWhere
([
'like'
,
'description'
,
$this
->
description
])
->
andFilterWhere
([
'like'
,
'image_url'
,
$this
->
image_url
])
->
andFilterWhere
([
'like'
,
'image_path'
,
$this
->
image_path
]);
return
$dataProvider
;
}
}
backend/modules/theme/views/category/_form.php
0 → 100644
View file @
4548d620
<?php
use
yii\helpers\Html
;
use
yii\bootstrap\ActiveForm
;
/* @var $this yii\web\View */
/* @var $model common\models\Category */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div
class=
"category-form"
>
<?php
$form
=
ActiveForm
::
begin
();
?>
<?php
echo
$form
->
errorSummary
(
$model
);
?>
<?php
echo
$form
->
field
(
$model
,
'name'
)
->
textInput
([
'maxlength'
=>
true
])
?>
<?php
echo
$form
->
field
(
$model
,
'slug'
)
->
textInput
([
'maxlength'
=>
true
])
?>
<?php
echo
$form
->
field
(
$model
,
'description'
)
->
textInput
([
'maxlength'
=>
true
])
?>
<?php
echo
$form
->
field
(
$model
,
'image_url'
)
->
textInput
([
'maxlength'
=>
true
])
?>
<?php
echo
$form
->
field
(
$model
,
'image_path'
)
->
textInput
([
'maxlength'
=>
true
])
?>
<?php
echo
$form
->
field
(
$model
,
'status'
)
->
textInput
()
?>
<?php
echo
$form
->
field
(
$model
,
'created_at'
)
->
textInput
()
?>
<?php
echo
$form
->
field
(
$model
,
'updated_at'
)
->
textInput
()
?>
<div
class=
"form-group"
>
<?php
echo
Html
::
submitButton
(
$model
->
isNewRecord
?
Yii
::
t
(
'backend'
,
'Create'
)
:
Yii
::
t
(
'backend'
,
'Update'
),
[
'class'
=>
$model
->
isNewRecord
?
'btn btn-success'
:
'btn btn-primary'
])
?>
</div>
<?php
ActiveForm
::
end
();
?>
</div>
backend/modules/theme/views/category/_search.php
0 → 100644
View file @
4548d620
<?php
use
yii\helpers\Html
;
use
yii\bootstrap\ActiveForm
;
/* @var $this yii\web\View */
/* @var $model backend\modules\theme\models\search\CategorySearch */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div
class=
"category-search"
>
<?php
$form
=
ActiveForm
::
begin
([
'action'
=>
[
'index'
],
'method'
=>
'get'
,
]);
?>
<?php
echo
$form
->
field
(
$model
,
'id'
)
?>
<?php
echo
$form
->
field
(
$model
,
'name'
)
?>
<?php
echo
$form
->
field
(
$model
,
'slug'
)
?>
<?php
echo
$form
->
field
(
$model
,
'description'
)
?>
<?php
echo
$form
->
field
(
$model
,
'image_url'
)
?>
<?php
// echo $form->field($model, 'image_path') ?>
<?
php
// echo $form->field($model, 'status') ?>
<?
php
// echo $form->field($model, 'created_at') ?>
<?
php
// echo $form->field($model, 'updated_at') ?>
<
div
class
="
form
-
group
">
<?php echo Html::submitButton(Yii::t('backend', 'Search'), ['class' => 'btn btn-primary']) ?>
<?php echo Html::resetButton(Yii::t('backend', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
backend/modules/theme/views/category/create.php
0 → 100644
View file @
4548d620
<?php
use
yii\helpers\Html
;
/* @var $this yii\web\View */
/* @var $model common\models\Category */
$this
->
title
=
Yii
::
t
(
'backend'
,
'Create {modelClass}'
,
[
'modelClass'
=>
'Category'
,
]);
$this
->
params
[
'breadcrumbs'
][]
=
[
'label'
=>
Yii
::
t
(
'backend'
,
'Categories'
),
'url'
=>
[
'index'
]];
$this
->
params
[
'breadcrumbs'
][]
=
$this
->
title
;
?>
<div
class=
"category-create"
>
<?php
echo
$this
->
render
(
'_form'
,
[
'model'
=>
$model
,
])
?>
</div>
backend/modules/theme/views/category/index.php
0 → 100644
View file @
4548d620
<?php
use
yii\helpers\Html
;
use
yii\grid\GridView
;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\theme\models\search\CategorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this
->
title
=
Yii
::
t
(
'backend'
,
'Categories'
);
$this
->
params
[
'breadcrumbs'
][]
=
$this
->
title
;
?>
<div
class=
"category-index"
>
<?php
// echo $this->render('_search', ['model' => $searchModel]); ?>
<
p
>
<?
php
echo
Html
::
a
(
Yii
::
t
(
'backend'
,
'Create {modelClass}'
,
[
'modelClass'
=>
'Category'
,
]),
[
'create'
],
[
'class'
=>
'btn btn-success'
])
?>
</p>
<?php
echo
GridView
::
widget
([
'dataProvider'
=>
$dataProvider
,
'filterModel'
=>
$searchModel
,
'columns'
=>
[
[
'class'
=>
'yii\grid\SerialColumn'
],
'id'
,
'name'
,
'slug'
,
'description'
,
'image_url:url'
,
// 'image_path',
// 'status',
// 'created_at',
// 'updated_at',
[
'class'
=>
'yii\grid\ActionColumn'
],
],
]);
?>
</div>
backend/modules/theme/views/category/update.php
0 → 100644
View file @
4548d620
<?php
use
yii\helpers\Html
;
/* @var $this yii\web\View */
/* @var $model common\models\Category */
$this
->
title
=
Yii
::
t
(
'backend'
,
'Update {modelClass}: '
,
[
'modelClass'
=>
'Category'
,
])
.
' '
.
$model
->
name
;
$this
->
params
[
'breadcrumbs'
][]
=
[
'label'
=>
Yii
::
t
(
'backend'
,
'Categories'
),
'url'
=>
[
'index'
]];
$this
->
params
[
'breadcrumbs'
][]
=
[
'label'
=>
$model
->
name
,
'url'
=>
[
'view'
,
'id'
=>
$model
->
id
]];
$this
->
params
[
'breadcrumbs'
][]
=
Yii
::
t
(
'backend'
,
'Update'
);
?>
<div
class=
"category-update"
>
<?php
echo
$this
->
render
(
'_form'
,
[
'model'
=>
$model
,
])
?>
</div>
backend/modules/theme/views/category/view.php
0 → 100644
View file @
4548d620
<?php
use
yii\helpers\Html
;
use
yii\widgets\DetailView
;
/* @var $this yii\web\View */
/* @var $model common\models\Category */
$this
->
title
=
$model
->
name
;
$this
->
params
[
'breadcrumbs'
][]
=
[
'label'
=>
Yii
::
t
(
'backend'
,
'Categories'
),
'url'
=>
[
'index'
]];
$this
->
params
[
'breadcrumbs'
][]
=
$this
->
title
;
?>
<div
class=
"category-view"
>
<p>
<?php
echo
Html
::
a
(
Yii
::
t
(
'backend'
,
'Update'
),
[
'update'
,
'id'
=>
$model
->
id
],
[
'class'
=>
'btn btn-primary'
])
?>
<?php
echo
Html
::
a
(
Yii
::
t
(
'backend'
,
'Delete'
),
[
'delete'
,
'id'
=>
$model
->
id
],
[
'class'
=>
'btn btn-danger'
,
'data'
=>
[
'confirm'
=>
Yii
::
t
(
'backend'
,
'Are you sure you want to delete this item?'
),
'method'
=>
'post'
,
],
])
?>
</p>
<?php
echo
DetailView
::
widget
([
'model'
=>
$model
,
'attributes'
=>
[
'id'
,
'name'
,
'slug'
,
'description'
,
'image_url:url'
,
'image_path'
,
'status'
,
'created_at'
,
'updated_at'
,
],
])
?>
</div>
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