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
bce3afcc
Commit
bce3afcc
authored
Oct 16, 2013
by
Luciano Baraglia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Module::getModule and Module::hasModule support for sub-modules - see #983
parent
e574f10c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
7 deletions
+30
-7
Module.php
framework/yii/base/Module.php
+30
-7
No files found.
framework/yii/base/Module.php
View file @
bce3afcc
...
...
@@ -333,7 +333,20 @@ abstract class Module extends Component
*/
public
function
hasModule
(
$id
)
{
return
isset
(
$this
->
_modules
[
$id
]);
if
(
strpos
(
$id
,
'/'
)
===
false
)
{
return
isset
(
$this
->
_modules
[
$id
]);
}
else
{
// it's a sub-module
$ids
=
explode
(
'/'
,
$id
);
$module
=
$this
;
foreach
(
$ids
as
$id
)
{
if
(
!
isset
(
$module
->
_modules
[
$id
]))
{
return
false
;
}
$module
=
$module
->
getModule
(
$id
);
}
return
true
;
}
}
/**
...
...
@@ -345,13 +358,23 @@ abstract class Module extends Component
*/
public
function
getModule
(
$id
,
$load
=
true
)
{
if
(
isset
(
$this
->
_modules
[
$id
]))
{
if
(
$this
->
_modules
[
$id
]
instanceof
Module
)
{
return
$this
->
_modules
[
$id
];
}
elseif
(
$load
)
{
Yii
::
trace
(
"Loading module:
$id
"
,
__METHOD__
);
return
$this
->
_modules
[
$id
]
=
Yii
::
createObject
(
$this
->
_modules
[
$id
],
$id
,
$this
);
if
(
strpos
(
$id
,
'/'
)
===
false
)
{
if
(
isset
(
$this
->
_modules
[
$id
]))
{
if
(
$this
->
_modules
[
$id
]
instanceof
Module
)
{
return
$this
->
_modules
[
$id
];
}
elseif
(
$load
)
{
Yii
::
trace
(
"Loading module:
$id
"
,
__METHOD__
);
return
$this
->
_modules
[
$id
]
=
Yii
::
createObject
(
$this
->
_modules
[
$id
],
$id
,
$this
);
}
}
}
else
{
// it's a sub-module
$ids
=
explode
(
'/'
,
$id
);
$module
=
$this
;
foreach
(
$ids
as
$id
)
{
$module
=
$module
->
getModule
(
$id
);
}
return
$module
;
}
return
null
;
}
...
...
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