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
7dd1f884
Commit
7dd1f884
authored
Apr 25, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for rest to Html.
parent
f21499dd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
11 deletions
+23
-11
Html.php
framework/helpers/base/Html.php
+20
-7
Request.php
framework/web/Request.php
+3
-4
No files found.
framework/helpers/base/Html.php
View file @
7dd1f884
...
@@ -9,6 +9,7 @@ namespace yii\helpers\base;
...
@@ -9,6 +9,7 @@ namespace yii\helpers\base;
use
Yii
;
use
Yii
;
use
yii\base\InvalidParamException
;
use
yii\base\InvalidParamException
;
use
yii\web\Request
;
/**
/**
* Html provides a set of static methods for generating commonly used HTML tags.
* Html provides a set of static methods for generating commonly used HTML tags.
...
@@ -276,7 +277,10 @@ class Html
...
@@ -276,7 +277,10 @@ class Html
/**
/**
* Generates a form start tag.
* Generates a form start tag.
* @param array|string $action the form action URL. This parameter will be processed by [[url()]].
* @param array|string $action the form action URL. This parameter will be processed by [[url()]].
* @param string $method the form submission method, either "post" or "get" (case-insensitive)
* @param string $method the form submission method, such as "post", "get", "put", "delete" (case-insensitive).
* Since most browsers only support "post" and "get", if other methods are given, they will
* be simulated using "post", and a hidden input will be added which contains the actual method type.
* See [[\yii\web\Request::restVar]] for more details.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered.
* If a value is null, the corresponding attribute will not be rendered.
...
@@ -287,15 +291,24 @@ class Html
...
@@ -287,15 +291,24 @@ class Html
{
{
$action
=
static
::
url
(
$action
);
$action
=
static
::
url
(
$action
);
$hiddenInputs
=
array
();
if
(
strcasecmp
(
$method
,
'get'
)
&&
strcasecmp
(
$method
,
'post'
))
{
// simulate PUT, DELETE, etc. via POST
if
((
$request
=
Yii
::
$app
->
getRequest
())
instanceof
Request
)
{
$hiddenInputs
[]
=
static
::
hiddenInput
(
$request
->
restVar
,
$method
);
$method
=
'post'
;
}
}
if
(
!
strcasecmp
(
$method
,
'get'
)
&&
(
$pos
=
strpos
(
$action
,
'?'
))
!==
false
)
{
// query parameters in the action are ignored for GET method
// query parameters in the action are ignored for GET method
// we use hidden fields to add them back
// we use hidden fields to add them back
$hiddens
=
array
();
if
(
!
strcasecmp
(
$method
,
'get'
)
&&
(
$pos
=
strpos
(
$action
,
'?'
))
!==
false
)
{
foreach
(
explode
(
'&'
,
substr
(
$action
,
$pos
+
1
))
as
$pair
)
{
foreach
(
explode
(
'&'
,
substr
(
$action
,
$pos
+
1
))
as
$pair
)
{
if
((
$pos1
=
strpos
(
$pair
,
'='
))
!==
false
)
{
if
((
$pos1
=
strpos
(
$pair
,
'='
))
!==
false
)
{
$hiddens
[]
=
static
::
hiddenInput
(
urldecode
(
substr
(
$pair
,
0
,
$pos1
)),
urldecode
(
substr
(
$pair
,
$pos1
+
1
)));
$hidden
Input
s
[]
=
static
::
hiddenInput
(
urldecode
(
substr
(
$pair
,
0
,
$pos1
)),
urldecode
(
substr
(
$pair
,
$pos1
+
1
)));
}
else
{
}
else
{
$hiddens
[]
=
static
::
hiddenInput
(
urldecode
(
$pair
),
''
);
$hidden
Input
s
[]
=
static
::
hiddenInput
(
urldecode
(
$pair
),
''
);
}
}
}
}
$action
=
substr
(
$action
,
0
,
$pos
);
$action
=
substr
(
$action
,
0
,
$pos
);
...
@@ -304,8 +317,8 @@ class Html
...
@@ -304,8 +317,8 @@ class Html
$options
[
'action'
]
=
$action
;
$options
[
'action'
]
=
$action
;
$options
[
'method'
]
=
$method
;
$options
[
'method'
]
=
$method
;
$form
=
static
::
beginTag
(
'form'
,
$options
);
$form
=
static
::
beginTag
(
'form'
,
$options
);
if
(
$hiddens
!==
array
())
{
if
(
$hidden
Input
s
!==
array
())
{
$form
.=
"
\n
"
.
implode
(
"
\n
"
,
$hiddens
);
$form
.=
"
\n
"
.
implode
(
"
\n
"
,
$hidden
Input
s
);
}
}
return
$form
;
return
$form
;
...
...
framework/web/Request.php
View file @
7dd1f884
...
@@ -27,8 +27,7 @@ class Request extends \yii\base\Request
...
@@ -27,8 +27,7 @@ class Request extends \yii\base\Request
public
$cookieValidationKey
;
public
$cookieValidationKey
;
/**
/**
* @var string|boolean the name of the POST parameter that is used to indicate if a request is a PUT or DELETE
* @var string|boolean the name of the POST parameter that is used to indicate if a request is a PUT or DELETE
* request tunneled through POST. If false, it means disabling REST request tunneled through POST.
* request tunneled through POST. Default to '_method'.
* Default to '_method'.
* @see getRequestMethod
* @see getRequestMethod
* @see getRestParams
* @see getRestParams
*/
*/
...
@@ -60,7 +59,7 @@ class Request extends \yii\base\Request
...
@@ -60,7 +59,7 @@ class Request extends \yii\base\Request
*/
*/
public
function
getRequestMethod
()
public
function
getRequestMethod
()
{
{
if
(
$this
->
restVar
!==
false
&&
isset
(
$_POST
[
$this
->
restVar
]))
{
if
(
isset
(
$_POST
[
$this
->
restVar
]))
{
return
strtoupper
(
$_POST
[
$this
->
restVar
]);
return
strtoupper
(
$_POST
[
$this
->
restVar
]);
}
else
{
}
else
{
return
isset
(
$_SERVER
[
'REQUEST_METHOD'
])
?
strtoupper
(
$_SERVER
[
'REQUEST_METHOD'
])
:
'GET'
;
return
isset
(
$_SERVER
[
'REQUEST_METHOD'
])
?
strtoupper
(
$_SERVER
[
'REQUEST_METHOD'
])
:
'GET'
;
...
@@ -123,7 +122,7 @@ class Request extends \yii\base\Request
...
@@ -123,7 +122,7 @@ class Request extends \yii\base\Request
public
function
getRestParams
()
public
function
getRestParams
()
{
{
if
(
$this
->
_restParams
===
null
)
{
if
(
$this
->
_restParams
===
null
)
{
if
(
$this
->
restVar
!==
false
&&
isset
(
$_POST
[
$this
->
restVar
]))
{
if
(
isset
(
$_POST
[
$this
->
restVar
]))
{
$this
->
_restParams
=
$_POST
;
$this
->
_restParams
=
$_POST
;
}
else
{
}
else
{
$this
->
_restParams
=
array
();
$this
->
_restParams
=
array
();
...
...
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