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
a5ee5b84
Commit
a5ee5b84
authored
Mar 22, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
view WIP
parent
2ecf1d92
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
249 additions
and
173 deletions
+249
-173
Controller.php
framework/base/Controller.php
+8
-44
View.php
framework/base/View.php
+100
-85
Widget.php
framework/base/Widget.php
+2
-44
Clip.php
framework/widgets/Clip.php
+58
-0
ContentDecorator.php
framework/widgets/ContentDecorator.php
+81
-0
No files found.
framework/base/Controller.php
View file @
a5ee5b84
...
@@ -304,9 +304,13 @@ class Controller extends Component
...
@@ -304,9 +304,13 @@ class Controller extends Component
*/
*/
public
function
render
(
$view
,
$params
=
array
())
public
function
render
(
$view
,
$params
=
array
())
{
{
$
viewFile
=
$this
->
findViewFile
(
$view
);
$
output
=
Yii
::
$app
->
getView
()
->
render
(
$view
,
$params
,
$this
);
$layoutFile
=
$this
->
findLayoutFile
();
$layoutFile
=
$this
->
findLayoutFile
();
return
Yii
::
$app
->
getView
()
->
render
(
$this
,
$viewFile
,
$params
,
$layoutFile
);
if
(
$layoutFile
!==
false
)
{
return
Yii
::
$app
->
getView
()
->
renderFile
(
$layoutFile
,
array
(
'content'
=>
$output
),
$this
);
}
else
{
return
$output
;
}
}
}
/**
/**
...
@@ -319,7 +323,7 @@ class Controller extends Component
...
@@ -319,7 +323,7 @@ class Controller extends Component
*/
*/
public
function
renderPartial
(
$view
,
$params
=
array
())
public
function
renderPartial
(
$view
,
$params
=
array
())
{
{
return
$this
->
renderFile
(
$this
->
findViewFile
(
$view
),
$param
s
);
return
Yii
::
$app
->
getView
()
->
render
(
$view
,
$params
,
$thi
s
);
}
}
/**
/**
...
@@ -331,7 +335,7 @@ class Controller extends Component
...
@@ -331,7 +335,7 @@ class Controller extends Component
*/
*/
public
function
renderFile
(
$file
,
$params
=
array
())
public
function
renderFile
(
$file
,
$params
=
array
())
{
{
return
Yii
::
$app
->
getView
()
->
render
(
$this
,
$file
,
$param
s
);
return
Yii
::
$app
->
getView
()
->
render
File
(
$file
,
$params
,
$thi
s
);
}
}
/**
/**
...
@@ -346,46 +350,6 @@ class Controller extends Component
...
@@ -346,46 +350,6 @@ class Controller 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
(
$view
)
{
if
(
strncmp
(
$view
,
'@'
,
1
)
===
0
)
{
// e.g. "@app/views/common"
$file
=
Yii
::
getAlias
(
$view
);
}
elseif
(
strncmp
(
$view
,
'/'
,
1
)
!==
0
)
{
// e.g. "index"
$file
=
$this
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
$view
;
}
elseif
(
strncmp
(
$view
,
'//'
,
2
)
!==
0
)
{
// e.g. "/site/index"
$file
=
$this
->
module
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
ltrim
(
$view
,
'/'
);
}
else
{
// e.g. "//layouts/main"
$file
=
Yii
::
$app
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
ltrim
(
$view
,
'/'
);
}
if
(
FileHelper
::
getExtension
(
$file
)
===
''
)
{
$file
.=
'.php'
;
}
return
$file
;
}
/**
* Finds the applicable layout file.
* Finds the applicable layout file.
*
*
* This method locates an applicable layout file via two steps.
* This method locates an applicable layout file via two steps.
...
...
framework/base/View.php
View file @
a5ee5b84
This diff is collapsed.
Click to expand it.
framework/base/Widget.php
View file @
a5ee5b84
...
@@ -80,8 +80,7 @@ class Widget extends Component
...
@@ -80,8 +80,7 @@ class Widget extends Component
*/
*/
public
function
render
(
$view
,
$params
=
array
())
public
function
render
(
$view
,
$params
=
array
())
{
{
$file
=
$this
->
findViewFile
(
$view
);
return
Yii
::
$app
->
getView
()
->
render
(
$view
,
$params
,
$this
);
return
Yii
::
$app
->
getView
()
->
render
(
$this
,
$file
,
$params
);
}
}
/**
/**
...
@@ -93,7 +92,7 @@ class Widget extends Component
...
@@ -93,7 +92,7 @@ class Widget extends Component
*/
*/
public
function
renderFile
(
$file
,
$params
=
array
())
public
function
renderFile
(
$file
,
$params
=
array
())
{
{
return
Yii
::
$app
->
getView
()
->
render
(
$this
,
$file
,
$param
s
);
return
Yii
::
$app
->
getView
()
->
render
File
(
$file
,
$params
,
$thi
s
);
}
}
/**
/**
...
@@ -107,44 +106,4 @@ class Widget extends Component
...
@@ -107,44 +106,4 @@ class Widget extends Component
$class
=
new
\ReflectionClass
(
$className
);
$class
=
new
\ReflectionClass
(
$className
);
return
dirname
(
$class
->
getFileName
())
.
DIRECTORY_SEPARATOR
.
'views'
;
return
dirname
(
$class
->
getFileName
())
.
DIRECTORY_SEPARATOR
.
'views'
;
}
}
/**
* Finds the view file based on the given view name.
*
* The 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
*/
public
function
findViewFile
(
$view
)
{
if
(
strncmp
(
$view
,
'@'
,
1
)
===
0
)
{
// e.g. "@app/views/common"
$file
=
Yii
::
getAlias
(
$view
);
}
elseif
(
strncmp
(
$view
,
'/'
,
1
)
!==
0
)
{
// e.g. "index"
$file
=
$this
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
$view
;
}
elseif
(
strncmp
(
$view
,
'//'
,
2
)
!==
0
&&
Yii
::
$app
->
controller
!==
null
)
{
// e.g. "/site/index"
$file
=
Yii
::
$app
->
controller
->
module
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
ltrim
(
$view
,
'/'
);
}
else
{
// e.g. "//layouts/main"
$file
=
Yii
::
$app
->
getViewPath
()
.
DIRECTORY_SEPARATOR
.
ltrim
(
$view
,
'/'
);
}
if
(
FileHelper
::
getExtension
(
$file
)
===
''
)
{
$file
.=
'.php'
;
}
return
$file
;
}
}
}
\ No newline at end of file
framework/widgets/Clip.php
0 → 100644
View file @
a5ee5b84
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\widgets
;
use
Yii
;
use
yii\base\Widget
;
use
yii\base\View
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
Clip
extends
Widget
{
/**
* @var string the ID of this clip.
*/
public
$id
;
/**
* @var View the view object for keeping the clip. If not set, the view registered with the application
* will be used.
*/
public
$view
;
/**
* @var boolean whether to render the clip content in place. Defaults to false,
* meaning the captured clip will not be displayed.
*/
public
$renderInPlace
=
false
;
/**
* Starts recording a clip.
*/
public
function
init
()
{
ob_start
();
ob_implicit_flush
(
false
);
}
/**
* Ends recording a clip.
* This method stops output buffering and saves the rendering result as a named clip in the controller.
*/
public
function
run
()
{
$clip
=
ob_get_clean
();
if
(
$this
->
renderClip
)
{
echo
$clip
;
}
$view
=
$this
->
view
!==
null
?
$this
->
view
:
Yii
::
$app
->
getView
();
$view
->
clips
[
$this
->
id
]
=
$clip
;
}
}
\ No newline at end of file
framework/widgets/ContentDecorator.php
0 → 100644
View file @
a5ee5b84
<?php
/**
* CContentDecorator class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
/**
* CContentDecorator decorates the content it encloses with the specified view.
*
* CContentDecorator is mostly used to implement nested layouts, i.e., a layout
* is embedded within another layout. {@link CBaseController} defines a pair of
* convenient methods to use CContentDecorator:
* <pre>
* $this->beginContent('path/to/view');
* // ... content to be decorated
* $this->endContent();
* </pre>
*
* The property {@link view} specifies the name of the view that is used to
* decorate the content. In the view, the content being decorated may be
* accessed with variable <code>$content</code>.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @package system.web.widgets
* @since 1.0
*/
class
CContentDecorator
extends
COutputProcessor
{
/**
* @var mixed the name of the view that will be used to decorate the captured content.
* If this property is null (default value), the default layout will be used as
* the decorative view. Note that if the current controller does not belong to
* any module, the default layout refers to the application's {@link CWebApplication::layout default layout};
* If the controller belongs to a module, the default layout refers to the module's
* {@link CWebModule::layout default layout}.
*/
public
$view
;
/**
* @var array the variables (name=>value) to be extracted and made available in the decorative view.
*/
public
$data
=
array
();
/**
* Processes the captured output.
* This method decorates the output with the specified {@link view}.
* @param string $output the captured output to be processed
*/
public
function
processOutput
(
$output
)
{
$output
=
$this
->
decorate
(
$output
);
parent
::
processOutput
(
$output
);
}
/**
* Decorates the content by rendering a view and embedding the content in it.
* The content being embedded can be accessed in the view using variable <code>$content</code>
* The decorated content will be displayed directly.
* @param string $content the content to be decorated
* @return string the decorated content
*/
protected
function
decorate
(
$content
)
{
$owner
=
$this
->
getOwner
();
if
(
$this
->
view
===
null
)
$viewFile
=
Yii
::
app
()
->
getController
()
->
getLayoutFile
(
null
);
else
$viewFile
=
$owner
->
getViewFile
(
$this
->
view
);
if
(
$viewFile
!==
false
)
{
$data
=
$this
->
data
;
$data
[
'content'
]
=
$content
;
return
$owner
->
renderFile
(
$viewFile
,
$data
,
true
);
}
else
return
$content
;
}
}
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