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
05f7df30
Commit
05f7df30
authored
Mar 09, 2014
by
Christian Nadolle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
console/Controller support local options per action
parent
80cb3e71
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
Controller.php
framework/console/Controller.php
+27
-0
No files found.
framework/console/Controller.php
View file @
05f7df30
...
@@ -67,6 +67,16 @@ class Controller extends \yii\base\Controller
...
@@ -67,6 +67,16 @@ class Controller extends \yii\base\Controller
public
function
runAction
(
$id
,
$params
=
[])
public
function
runAction
(
$id
,
$params
=
[])
{
{
if
(
!
empty
(
$params
))
{
if
(
!
empty
(
$params
))
{
// extract valid local options first so that they don't throw "unknown option"- exception below.
$options
=
$this
->
localOptions
(
$id
);
foreach
(
$params
as
$name
=>
$value
)
{
if
(
in_array
(
$name
,
$options
,
true
))
{
$default
=
$this
->
$name
;
$this
->
$name
=
is_array
(
$default
)
?
preg_split
(
'/\s*,\s*/'
,
$value
)
:
$value
;
unset
(
$params
[
$name
]);
}
}
// populate global options here so that they are available in beforeAction().
// populate global options here so that they are available in beforeAction().
$options
=
$this
->
globalOptions
();
$options
=
$this
->
globalOptions
();
foreach
(
$params
as
$name
=>
$value
)
{
foreach
(
$params
as
$name
=>
$value
)
{
...
@@ -266,4 +276,21 @@ class Controller extends \yii\base\Controller
...
@@ -266,4 +276,21 @@ class Controller extends \yii\base\Controller
{
{
return
[
'color'
,
'interactive'
];
return
[
'color'
,
'interactive'
];
}
}
/**
* Returns the names of valid options local to the action (id)
* A local option requires the existence of a public member variable whose
* name is the option name.
* Child classes may override this method to specify possible local options.
*
* Note that the values setting via global options are not available
* until [[beforeAction()]] is being called.
*
* @param $id action name
* @return array the names of the options valid for this action (in addition to global options above)
*/
public
function
localOptions
(
$id
)
{
return
[];
}
}
}
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