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
2d8a465c
Commit
2d8a465c
authored
May 14, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #257: removed the $view parameter from widget methods.
parent
472902fa
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
53 additions
and
45 deletions
+53
-45
main.php
apps/bootstrap/protected/views/layouts/main.php
+3
-3
contact.php
apps/bootstrap/protected/views/site/contact.php
+2
-2
login.php
apps/bootstrap/protected/views/site/login.php
+1
-1
upgrade-from-v1.md
docs/guide/upgrade-from-v1.md
+1
-1
Controller.php
yii/base/Controller.php
+1
-0
View.php
yii/base/View.php
+6
-3
Widget.php
yii/base/Widget.php
+35
-31
Pagination.php
yii/web/Pagination.php
+1
-1
Breadcrumbs.php
yii/widgets/Breadcrumbs.php
+2
-2
Menu.php
yii/widgets/Menu.php
+1
-1
No files found.
apps/bootstrap/protected/views/layouts/main.php
View file @
2d8a465c
...
...
@@ -27,7 +27,7 @@ $this->registerAssetBundle('app');
<div
class=
"navbar"
>
<div
class=
"navbar-inner"
>
<div
class=
"container"
>
<?php
echo
Menu
::
widget
(
$this
,
array
(
<?php
echo
Menu
::
widget
(
array
(
'options'
=>
array
(
'class'
=>
'nav'
),
'items'
=>
array
(
array
(
'label'
=>
'Home'
,
'url'
=>
array
(
'/site/index'
)),
...
...
@@ -44,7 +44,7 @@ $this->registerAssetBundle('app');
<!-- /.navbar -->
</div>
<?php
echo
Breadcrumbs
::
widget
(
$this
,
array
(
<?php
echo
Breadcrumbs
::
widget
(
array
(
'links'
=>
isset
(
$this
->
params
[
'breadcrumbs'
])
?
$this
->
params
[
'breadcrumbs'
]
:
array
(),
));
?>
<?php
echo
$content
;
?>
...
...
@@ -60,7 +60,7 @@ $this->registerAssetBundle('app');
</div>
<?php
$this
->
endBody
();
?>
</div>
<?php
echo
Toolbar
::
widget
(
$this
);
?>
<?php
echo
Toolbar
::
widget
();
?>
</body>
</html>
<?php
$this
->
endPage
();
?>
apps/bootstrap/protected/views/site/contact.php
View file @
2d8a465c
...
...
@@ -23,7 +23,7 @@ $this->params['breadcrumbs'][] = $this->title;
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p>
<?php
$form
=
ActiveForm
::
begin
(
$this
,
array
(
<?php
$form
=
ActiveForm
::
begin
(
array
(
'options'
=>
array
(
'class'
=>
'form-horizontal'
),
'fieldConfig'
=>
array
(
'inputOptions'
=>
array
(
'class'
=>
'input-xlarge'
)),
));
?>
...
...
@@ -35,7 +35,7 @@ $this->params['breadcrumbs'][] = $this->title;
$field
=
$form
->
field
(
$model
,
'verifyCode'
);
echo
$field
->
begin
()
.
$field
->
label
()
.
Captcha
::
widget
(
$this
)
.
Captcha
::
widget
()
.
Html
::
activeTextInput
(
$model
,
'verifyCode'
,
array
(
'class'
=>
'input-medium'
))
.
$field
->
error
()
.
$field
->
end
();
...
...
apps/bootstrap/protected/views/site/login.php
View file @
2d8a465c
...
...
@@ -14,7 +14,7 @@ $this->params['breadcrumbs'][] = $this->title;
<p>
Please fill out the following fields to login:
</p>
<?php
$form
=
ActiveForm
::
begin
(
$this
,
array
(
'options'
=>
array
(
'class'
=>
'form-horizontal'
)));
?>
<?php
$form
=
ActiveForm
::
begin
(
array
(
'options'
=>
array
(
'class'
=>
'form-horizontal'
)));
?>
<?php
echo
$form
->
field
(
$model
,
'username'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'password'
)
->
passwordInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'rememberMe'
)
->
checkbox
();
?>
...
...
docs/guide/upgrade-from-v1.md
View file @
2d8a465c
...
...
@@ -218,7 +218,7 @@ methods of the `Widget` class. For example,
```
php
// $this refers to the View object
// Note that you have to "echo" the result to display it
echo
\yii\widgets\Menu
::
widget
(
$this
,
array
(
'items'
=>
$items
));
echo
\yii\widgets\Menu
::
widget
(
array
(
'items'
=>
$items
));
// $this refers to the View object
$form
=
\yii\widgets\ActiveForm
::
begin
(
$this
);
...
...
yii/base/Controller.php
View file @
2d8a465c
...
...
@@ -410,6 +410,7 @@ class Controller extends Component
* Returns the view object that can be used to render views or view files.
* The [[render()]], [[renderPartial()]] and [[renderFile()]] methods will use
* this view object to implement the actual view rendering.
* If not set, it will default to the "view" application component.
* @return View the view object that can be used to render views or view files.
*/
public
function
getView
()
...
...
yii/base/View.php
View file @
2d8a465c
...
...
@@ -373,9 +373,10 @@ class View extends Component
*/
public
function
beginBlock
(
$id
,
$renderInPlace
=
false
)
{
return
Block
::
begin
(
$this
,
array
(
return
Block
::
begin
(
array
(
'id'
=>
$id
,
'renderInPlace'
=>
$renderInPlace
,
'view'
=>
$this
,
));
}
...
...
@@ -406,9 +407,10 @@ class View extends Component
*/
public
function
beginContent
(
$viewFile
,
$params
=
array
())
{
return
ContentDecorator
::
begin
(
$this
,
array
(
return
ContentDecorator
::
begin
(
array
(
'viewFile'
=>
$viewFile
,
'params'
=>
$params
,
'view'
=>
$this
,
));
}
...
...
@@ -442,8 +444,9 @@ class View extends Component
public
function
beginCache
(
$id
,
$properties
=
array
())
{
$properties
[
'id'
]
=
$id
;
$properties
[
'view'
]
=
$this
;
/** @var $cache FragmentCache */
$cache
=
FragmentCache
::
begin
(
$
this
,
$
properties
);
$cache
=
FragmentCache
::
begin
(
$properties
);
if
(
$cache
->
getCachedContent
()
!==
false
)
{
$this
->
endCache
();
return
false
;
...
...
yii/base/Widget.php
View file @
2d8a465c
...
...
@@ -18,16 +18,6 @@ use Yii;
class
Widget
extends
Component
{
/**
* @var View the view object that this widget is associated with.
* The widget will use this view object to register any needed assets.
* This property is also required by [[render()]] and [[renderFile()]].
*/
public
$view
;
/**
* @var string id of the widget.
*/
private
$_id
;
/**
* @var integer a counter used to generate [[id]] for widgets.
* @internal
*/
...
...
@@ -39,32 +29,19 @@ class Widget extends Component
*/
public
static
$_stack
=
array
();
/**
* Constructor.
* @param View $view the view object that this widget is associated with.
* The widget will use this view object to register any needed assets.
* It is also required by [[render()]] and [[renderFile()]].
* @param array $config name-value pairs that will be used to initialize the object properties
*/
public
function
__construct
(
$view
,
$config
=
array
())
{
$this
->
view
=
$view
;
parent
::
__construct
(
$config
);
}
/**
* Begins a widget.
* This method creates an instance of the calling class. It will apply the configuration
* to the created instance. A matching [[end()]] call should be called later.
* @param View $view the view object that the newly created widget is associated with.
* @param array $config name-value pairs that will be used to initialize the object properties
* @return Widget the newly created widget instance
*/
public
static
function
begin
(
$
view
,
$
config
=
array
())
public
static
function
begin
(
$config
=
array
())
{
$config
[
'class'
]
=
get_called_class
();
/** @var Widget $widget */
$widget
=
Yii
::
createObject
(
$config
,
$view
);
$widget
=
Yii
::
createObject
(
$config
);
self
::
$_stack
[]
=
$widget
;
return
$widget
;
}
...
...
@@ -93,21 +70,22 @@ class Widget extends Component
/**
* Creates a widget instance and runs it.
* The widget rendering result is returned by this method.
* @param View $view the view object that the newly created widget is associated with.
* @param array $config name-value pairs that will be used to initialize the object properties
* @return string the rendering result of the widget.
*/
public
static
function
widget
(
$
view
,
$
config
=
array
())
public
static
function
widget
(
$config
=
array
())
{
ob_start
();
ob_implicit_flush
(
false
);
/** @var Widget $widget */
$config
[
'class'
]
=
get_called_class
();
$widget
=
Yii
::
createObject
(
$config
,
$view
);
$widget
=
Yii
::
createObject
(
$config
);
$widget
->
run
();
return
ob_get_clean
();
}
private
$_id
;
/**
* Returns the ID of the widget.
* @param boolean $autoGenerate whether to generate an ID if it is not set previously
...
...
@@ -130,6 +108,32 @@ class Widget extends Component
$this
->
_id
=
$value
;
}
private
$_view
;
/**
* Returns the view object that can be used to render views or view files.
* The [[render()]] and [[renderFile()]] methods will use
* this view object to implement the actual view rendering.
* If not set, it will default to the "view" application component.
* @return View the view object that can be used to render views or view files.
*/
public
function
getView
()
{
if
(
$this
->
_view
===
null
)
{
$this
->
_view
=
Yii
::
$app
->
getView
();
}
return
$this
->
_view
;
}
/**
* Sets the view object to be used by this widget.
* @param View $view the view object that can be used to render views or view files.
*/
public
function
setView
(
$view
)
{
$this
->
_view
=
$view
;
}
/**
* Executes the widget.
*/
...
...
@@ -159,7 +163,7 @@ class Widget extends Component
public
function
render
(
$view
,
$params
=
array
())
{
$viewFile
=
$this
->
findViewFile
(
$view
);
return
$this
->
view
->
renderFile
(
$viewFile
,
$params
,
$this
);
return
$this
->
getView
()
->
renderFile
(
$viewFile
,
$params
,
$this
);
}
/**
...
...
@@ -171,7 +175,7 @@ class Widget extends Component
*/
public
function
renderFile
(
$file
,
$params
=
array
())
{
return
$this
->
view
->
renderFile
(
$file
,
$params
,
$this
);
return
$this
->
getView
()
->
renderFile
(
$file
,
$params
,
$this
);
}
/**
...
...
yii/web/Pagination.php
View file @
2d8a465c
...
...
@@ -47,7 +47,7 @@ use Yii;
* }
*
* // display pagination
* LinkPager::widget(
$this,
array(
* LinkPager::widget(array(
* 'pages' => $pages,
* ));
* ~~~
...
...
yii/widgets/Breadcrumbs.php
View file @
2d8a465c
...
...
@@ -23,7 +23,7 @@ use yii\helpers\Html;
*
* ~~~
* // $this is the view object currently being used
* echo Breadcrumbs::widget(
$this,
array(
* echo Breadcrumbs::widget(array(
* 'links' => array(
* array('label' => 'Sample Post', 'url' => array('post/edit', 'id' => 1)),
* 'Edit',
...
...
@@ -37,7 +37,7 @@ use yii\helpers\Html;
*
* ~~~
* // $this is the view object currently being used
* echo Breadcrumbs::widget(
$this,
array(
* echo Breadcrumbs::widget(array(
* 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
* ));
* ~~~
...
...
yii/widgets/Menu.php
View file @
2d8a465c
...
...
@@ -27,7 +27,7 @@ use yii\helpers\Html;
*
* ~~~
* // $this is the view object currently being used
* echo Menu::widget(
$this,
array(
* echo Menu::widget(array(
* 'items' => array(
* // Important: you need to specify url as 'controller/action',
* // not just as 'controller' even if default action is used.
...
...
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