Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
cd969509
Commit
cd969509
authored
Sep 24, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ActionColumn.
crud generator WIP.
parent
603da3f6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
1 deletion
+124
-1
controller.php
framework/yii/gii/generators/crud/templates/controller.php
+13
-0
index.php
framework/yii/gii/generators/crud/templates/views/index.php
+4
-0
view.php
framework/yii/gii/generators/crud/templates/views/view.php
+5
-1
ActionColumn.php
framework/yii/grid/ActionColumn.php
+102
-0
No files found.
framework/yii/gii/generators/crud/templates/controller.php
View file @
cd969509
...
@@ -28,12 +28,25 @@ use <?php echo ltrim($generator->searchModelClass, '\\'); ?>;
...
@@ -28,12 +28,25 @@ use <?php echo ltrim($generator->searchModelClass, '\\'); ?>;
use yii\data\ActiveDataProvider;
use yii\data\ActiveDataProvider;
use
<?php
echo
ltrim
(
$generator
->
baseControllerClass
,
'\\'
);
?>
;
use
<?php
echo
ltrim
(
$generator
->
baseControllerClass
,
'\\'
);
?>
;
use yii\web\HttpException;
use yii\web\HttpException;
use yii\web\VerbFilter;
/**
/**
*
<?php
echo
$controllerClass
;
?>
implements the CRUD actions for
<?php
echo
$modelClass
;
?>
model.
*
<?php
echo
$controllerClass
;
?>
implements the CRUD actions for
<?php
echo
$modelClass
;
?>
model.
*/
*/
class
<?php
echo
$controllerClass
;
?>
extends
<?php
echo
StringHelper
::
basename
(
$generator
->
baseControllerClass
)
.
"
\n
"
;
?>
class
<?php
echo
$controllerClass
;
?>
extends
<?php
echo
StringHelper
::
basename
(
$generator
->
baseControllerClass
)
.
"
\n
"
;
?>
{
{
public function behaviors()
{
return array(
'verbs' => array(
'class' => VerbFilter::className(),
'actions' => array(
'delete' => array('post'),
),
),
);
}
/**
/**
* Lists all
<?php
echo
$modelClass
;
?>
models.
* Lists all
<?php
echo
$modelClass
;
?>
models.
* @return mixed
* @return mixed
...
...
framework/yii/gii/generators/crud/templates/views/index.php
View file @
cd969509
...
@@ -54,6 +54,10 @@ foreach ($generator->getTableSchema()->columns as $column) {
...
@@ -54,6 +54,10 @@ foreach ($generator->getTableSchema()->columns as $column) {
}
}
}
}
?>
?>
array(
'class' => 'yii\grid\ActionColumn',
),
),
),
)); ?>
)); ?>
<?php
else
:
?>
<?php
else
:
?>
...
...
framework/yii/gii/generators/crud/templates/views/view.php
View file @
cd969509
...
@@ -31,7 +31,11 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -31,7 +31,11 @@ $this->params['breadcrumbs'][] = $this->title;
<div>
<div>
<?php
echo
'<?php'
;
?>
echo Html::a('Update', array('update',
<?php
echo
$urlParams
;
?>
), array('class' => 'btn btn-danger')); ?>
<?php
echo
'<?php'
;
?>
echo Html::a('Update', array('update',
<?php
echo
$urlParams
;
?>
), array('class' => 'btn btn-danger')); ?>
<?php
echo
'<?php'
;
?>
echo Html::a('Delete', array('delete',
<?php
echo
$urlParams
;
?>
), array('class' => 'btn btn-danger')); ?>
<?php
echo
'<?php'
;
?>
echo Html::a('Delete', array('delete',
<?php
echo
$urlParams
;
?>
), array(
'class' => 'btn btn-danger',
'data-confirm' => Yii::t('app', 'Are you sure to delete this item?'),
'data-method' => 'post',
)); ?>
</div>
</div>
<?php
echo
'<?php'
;
?>
echo DetailView::widget(array(
<?php
echo
'<?php'
;
?>
echo DetailView::widget(array(
...
...
framework/yii/grid/ActionColumn.php
0 → 100644
View file @
cd969509
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\grid
;
use
Yii
;
use
Closure
;
use
yii\helpers\Html
;
use
yii\helpers\Inflector
;
use
yii\helpers\StringHelper
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
ActionColumn
extends
Column
{
public
$template
=
'{view} {update} {delete}'
;
public
$buttons
=
array
();
public
$urlCreator
;
public
function
init
()
{
parent
::
init
();
$this
->
initDefaultButtons
();
}
protected
function
initDefaultButtons
()
{
if
(
!
isset
(
$this
->
buttons
[
'view'
]))
{
$this
->
buttons
[
'view'
]
=
function
(
$model
,
$column
)
{
/** @var ActionColumn $column */
$url
=
$column
->
createUrl
(
$model
,
'view'
);
return
Html
::
a
(
'<span class="glyphicon glyphicon-eye-open"></span>'
,
$url
,
array
(
'title'
=>
Yii
::
t
(
'yii'
,
'View'
),
));
};
}
if
(
!
isset
(
$this
->
buttons
[
'update'
]))
{
$this
->
buttons
[
'update'
]
=
function
(
$model
,
$column
)
{
/** @var ActionColumn $column */
$url
=
$column
->
createUrl
(
$model
,
'update'
);
return
Html
::
a
(
'<span class="glyphicon glyphicon-pencil"></span>'
,
$url
,
array
(
'title'
=>
Yii
::
t
(
'yii'
,
'Update'
),
));
};
}
if
(
!
isset
(
$this
->
buttons
[
'delete'
]))
{
$this
->
buttons
[
'delete'
]
=
function
(
$model
,
$column
)
{
/** @var ActionColumn $column */
$url
=
$column
->
createUrl
(
$model
,
'delete'
);
return
Html
::
a
(
'<span class="glyphicon glyphicon-trash"></span>'
,
$url
,
array
(
'title'
=>
Yii
::
t
(
'yii'
,
'Delete'
),
'data-confirm'
=>
Yii
::
t
(
'yii'
,
'Are you sure to delete this item?'
),
'data-method'
=>
'post'
,
));
};
}
}
/**
* @param \yii\db\ActiveRecord $model
* @param string $action
* @return string
*/
public
function
createUrl
(
$model
,
$action
)
{
if
(
$this
->
urlCreator
instanceof
Closure
)
{
return
call_user_func
(
$this
->
urlCreator
,
$model
,
$action
);
}
else
{
$route
=
Inflector
::
camel2id
(
StringHelper
::
basename
(
get_class
(
$model
)))
.
'/'
.
$action
;
$params
=
$model
->
getPrimaryKey
(
true
);
if
(
count
(
$params
)
===
1
)
{
$params
=
array
(
'id'
=>
reset
(
$params
));
}
return
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
,
$params
);
}
}
/**
* Renders the data cell content.
* @param mixed $model the data model
* @param integer $index the zero-based index of the data model among the models array returned by [[dataProvider]].
* @return string the rendering result
*/
protected
function
renderDataCellContent
(
$model
,
$index
)
{
$column
=
$this
;
return
preg_replace_callback
(
'/\\{(\w+)\\}/'
,
function
(
$matches
)
use
(
$model
,
$column
)
{
$name
=
$matches
[
1
];
if
(
isset
(
$column
->
buttons
[
$name
]))
{
return
call_user_func
(
$column
->
buttons
[
$name
],
$model
,
$column
);
}
else
{
return
''
;
}
},
$this
->
template
);
}
}
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