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
b77ea4dc
Commit
b77ea4dc
authored
Sep 04, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow generator to define actions.
parent
8c753676
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
DefaultController.php
framework/yii/gii/controllers/DefaultController.php
+33
-0
No files found.
framework/yii/gii/controllers/DefaultController.php
View file @
b77ea4dc
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
namespace
yii\gii\controllers
;
namespace
yii\gii\controllers
;
use
Yii
;
use
yii\web\Controller
;
use
yii\web\Controller
;
use
yii\web\HttpException
;
use
yii\web\HttpException
;
...
@@ -86,6 +87,26 @@ class DefaultController extends Controller
...
@@ -86,6 +87,26 @@ class DefaultController extends Controller
throw
new
HttpException
(
404
,
"Code file not found:
$file
"
);
throw
new
HttpException
(
404
,
"Code file not found:
$file
"
);
}
}
/**
* Runs an action defined in the generator.
* Given an action named "xyz", the method "actionXyz()" in the generator will be called.
* If the method does not exist, a 400 HTTP exception will be thrown.
* @param string $id the ID of the generator
* @param string $name the action name
* @return mixed the result of the action.
* @throws HttpException if the action method does not exist.
*/
public
function
actionAction
(
$id
,
$name
)
{
$generator
=
$this
->
loadGenerator
(
$id
);
$method
=
'action'
.
$name
;
if
(
method_exists
(
$generator
,
$method
))
{
return
$generator
->
$method
();
}
else
{
throw
new
HttpException
(
400
,
"Unknown generator action:
$name
"
);
}
}
public
function
createUrl
(
$route
,
$params
=
array
())
public
function
createUrl
(
$route
,
$params
=
array
())
{
{
if
(
!
isset
(
$params
[
'id'
])
&&
$this
->
generator
!==
null
)
{
if
(
!
isset
(
$params
[
'id'
])
&&
$this
->
generator
!==
null
)
{
...
@@ -99,6 +120,18 @@ class DefaultController extends Controller
...
@@ -99,6 +120,18 @@ class DefaultController extends Controller
return
parent
::
createUrl
(
$route
,
$params
);
return
parent
::
createUrl
(
$route
,
$params
);
}
}
public
function
createActionUrl
(
$name
,
$params
=
array
())
{
foreach
(
$this
->
module
->
generators
as
$id
=>
$generator
)
{
if
(
$generator
===
$this
->
generator
)
{
$params
[
'id'
]
=
$id
;
break
;
}
}
$params
[
'name'
]
=
$name
;
return
parent
::
createUrl
(
'action'
,
$params
);
}
/**
/**
* Loads the generator with the specified ID.
* Loads the generator with the specified ID.
* @param string $id the ID of the generator to be loaded.
* @param string $id the ID of the generator to be loaded.
...
...
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