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
2ecf1d92
Commit
2ecf1d92
authored
Mar 22, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
view sip
parent
1d48d01e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
16 deletions
+47
-16
Controller.php
framework/base/Controller.php
+1
-3
View.php
framework/base/View.php
+46
-13
No files found.
framework/base/Controller.php
View file @
2ecf1d92
...
@@ -414,12 +414,10 @@ class Controller extends Component
...
@@ -414,12 +414,10 @@ class Controller extends Component
*/
*/
protected
function
findLayoutFile
()
protected
function
findLayoutFile
()
{
{
/** @var $module Module */
if
(
is_string
(
$this
->
layout
))
{
$module
=
$this
->
module
;
$module
=
$this
->
module
;
if
(
is_string
(
$this
->
layout
))
{
$view
=
$this
->
layout
;
$view
=
$this
->
layout
;
}
elseif
(
$this
->
layout
===
null
)
{
}
elseif
(
$this
->
layout
===
null
)
{
$module
=
$this
->
module
;
while
(
$module
!==
null
&&
$module
->
layout
===
null
)
{
while
(
$module
!==
null
&&
$module
->
layout
===
null
)
{
$module
=
$module
->
module
;
$module
=
$module
->
module
;
}
}
...
...
framework/base/View.php
View file @
2ecf1d92
...
@@ -79,20 +79,10 @@ class View extends Component
...
@@ -79,20 +79,10 @@ class View extends Component
* @return string the rendering result
* @return string the rendering result
* @throws InvalidParamException if the view file or the layout file does not exist.
* @throws InvalidParamException if the view file or the layout file does not exist.
*/
*/
public
function
render
(
$
context
,
$viewFile
,
$params
=
array
(),
$layoutFile
=
false
)
public
function
render
(
$
view
,
$params
=
array
()
)
{
{
$oldContext
=
$this
->
context
;
$viewFile
=
$this
->
findViewFile
(
$this
->
context
,
$view
);
$this
->
context
=
$context
;
return
$this
->
renderFile
(
$viewFile
,
$params
);
$content
=
$this
->
renderFile
(
$viewFile
,
$params
);
if
(
$layoutFile
!==
false
)
{
$content
=
$this
->
renderFile
(
$layoutFile
,
array
(
'content'
=>
$content
));
}
$this
->
context
=
$oldContext
;
return
$content
;
}
}
/**
/**
...
@@ -156,6 +146,49 @@ class View extends Component
...
@@ -156,6 +146,49 @@ class View extends Component
}
}
/**
/**
* Finds the view file based on the given view name.
*
* A view name can be specified in one of the following formats:
*
* - path alias (e.g. "@app/views/site/index");
* - absolute path within application (e.g. "//site/index"): the view name starts with double slashes.
* The actual view file will be looked for under the [[Application::viewPath|view path]] of the application.
* - absolute path within module (e.g. "/site/index"): the view name starts with a single slash.
* The actual view file will be looked for under the [[Module::viewPath|view path]] of the currently
* active module.
* - relative path (e.g. "index"): the actual view file will be looked for under [[viewPath]].
*
* If the view name does not contain a file extension, it will use the default one `.php`.
*
* @param string $view the view name or the path alias of the view file.
* @return string the view file path. Note that the file may not exist.
* @throws InvalidParamException if the view file is an invalid path alias
*/
protected
function
findViewFile
(
$context
,
$view
)
{
if
(
FileHelper
::
getExtension
(
$view
)
===
''
)
{
$view
.=
'.php'
;
}
if
(
strncmp
(
$view
,
'//'
,
2
)
===
0
)
{
// e.g. "//layouts/main"
$file
=
Yii
::
$app
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
ltrim
(
$view
,
'/'
);
}
elseif
(
strncmp
(
$view
,
'/'
,
1
)
===
0
)
{
// e.g. "/site/index"
$file
=
Yii
::
$app
->
controller
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
ltrim
(
$view
,
'/'
);
}
elseif
(
strncmp
(
$view
,
'@'
,
1
)
!==
0
)
{
// e.g. "index" or "view/item"
if
(
method_exists
(
$context
,
'getViewPath'
))
{
$file
=
$context
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
$view
;
}
else
{
$file
=
Yii
::
$app
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
$view
;
}
}
return
$file
;
}
/**
* Creates a widget.
* Creates a widget.
* This method will use [[Yii::createObject()]] to create the widget.
* This method will use [[Yii::createObject()]] to create the widget.
* @param string $class the widget class name or path alias
* @param string $class the widget class name or path alias
...
...
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