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
155e9c6c
Commit
155e9c6c
authored
Oct 28, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor refactoring of view resolving code.
parent
0258c151
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
14 deletions
+14
-14
View.php
framework/yii/base/View.php
+7
-3
ViewContextInterface.php
framework/yii/base/ViewContextInterface.php
+4
-8
Widget.php
framework/yii/base/Widget.php
+3
-3
No files found.
framework/yii/base/View.php
View file @
155e9c6c
...
...
@@ -225,8 +225,8 @@ class View extends Component
* on how to specify this parameter.
* @param object $context the context that the view should be used to search the view file. If null,
* existing [[context]] will be used.
* @throws InvalidCallException if [[context]] is required and invalid.
* @return string the view file path. Note that the file may not exist.
* @throws InvalidCallException if [[context]] is required and invalid.
*/
protected
function
findViewFile
(
$view
,
$context
=
null
)
{
...
...
@@ -236,10 +236,14 @@ class View extends Component
}
elseif
(
strncmp
(
$view
,
'//'
,
2
)
===
0
)
{
// e.g. "//layouts/main"
$file
=
Yii
::
$app
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
ltrim
(
$view
,
'/'
);
}
elseif
(
strncmp
(
$view
,
'/'
,
1
)
===
0
&&
Yii
::
$app
->
controller
!==
null
)
{
}
elseif
(
strncmp
(
$view
,
'/'
,
1
)
===
0
)
{
// e.g. "/site/index"
if
(
Yii
::
$app
->
controller
!==
null
)
{
$file
=
Yii
::
$app
->
controller
->
module
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
ltrim
(
$view
,
'/'
);
}
else
{
throw
new
InvalidCallException
(
"Unable to locate view file for view '
$view
': no active controller."
);
}
}
else
{
// context required
if
(
$context
===
null
)
{
$context
=
$this
->
context
;
...
...
@@ -247,7 +251,7 @@ class View extends Component
if
(
$context
instanceof
ViewContextInterface
)
{
$file
=
$context
->
findViewFile
(
$view
);
}
else
{
throw
new
InvalidCallException
(
'Current context is not supported.'
);
throw
new
InvalidCallException
(
"Unable to locate view file for view '
$view
': no active view context."
);
}
}
...
...
framework/yii/base/ViewContextInterface.php
View file @
155e9c6c
...
...
@@ -8,13 +8,9 @@
namespace
yii\base
;
/**
* ViewContextInterface represents possible context for the view rendering.
* It determines the way the non-global view files are searched.
* This interface introduces method [[findViewFile]], which will be used
* at [[View::render()]] to determine the file by view name, which does
* not match default format.
* ViewContextInterface is the interface that should implemented by classes who want to support relative view names.
*
*
@see View
*
The method [[findViewFile()]] should be implemented to convert a relative view name into a file path.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
...
...
@@ -22,8 +18,8 @@ namespace yii\base;
interface
ViewContextInterface
{
/**
* Finds the view file
based on the given
view name.
* @param string $view
the view name
.
* Finds the view file
corresponding to the specified relative
view name.
* @param string $view
a relative view name. The name does NOT start with a slash
.
* @return string the view file path. Note that the file may not exist.
*/
public
function
findViewFile
(
$view
);
...
...
framework/yii/base/Widget.php
View file @
155e9c6c
...
...
@@ -8,6 +8,7 @@
namespace
yii\base
;
use
Yii
;
use
ReflectionClass
;
/**
* Widget is the base class for widgets.
...
...
@@ -189,8 +190,7 @@ class Widget extends Component implements ViewContextInterface
*/
public
function
getViewPath
()
{
$className
=
get_class
(
$this
);
$class
=
new
\ReflectionClass
(
$className
);
$class
=
new
ReflectionClass
(
$this
);
return
dirname
(
$class
->
getFileName
())
.
DIRECTORY_SEPARATOR
.
'views'
;
}
...
...
@@ -202,6 +202,6 @@ class Widget extends Component implements ViewContextInterface
*/
public
function
findViewFile
(
$view
)
{
return
$this
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
ltrim
(
$view
,
'/'
)
;
return
$this
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
$view
;
}
}
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