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
390a6c78
Commit
390a6c78
authored
Jul 23, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #4409: Upper case letters in subdirectory prefixes of controller IDs were…
Fixes #4409: Upper case letters in subdirectory prefixes of controller IDs were not properly handled
parent
4ac6777c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
9 deletions
+16
-9
structure-controllers.md
docs/guide/structure-controllers.md
+8
-5
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Module.php
framework/base/Module.php
+7
-4
No files found.
docs/guide/structure-controllers.md
View file @
390a6c78
...
...
@@ -112,11 +112,13 @@ For this reason, controller IDs are often nouns referring to the types of the re
For example, you may use
`article`
as the ID of a controller that handles article data.
By default, controller IDs should contain these characters only: English letters in lower case, digits,
underscores, dashes and forward slashes. For example,
`article`
,
`post-comment`
,
`admin/post2-comment`
are
all valid controller IDs,
while
`article?`
,
`PostComment`
,
`admin\post`
are not.
underscores, dashes and forward slashes. For example,
`article`
and
`post-comment`
are both valid controller IDs,
while
`article?`
,
`PostComment`
,
`admin\post`
are not.
The dashes in a controller ID are used to separate words, while the forward slashes to organize controllers in
sub-directories.
A controller ID may also contain a subdirectory prefix. For example,
`admin/article`
stands for an
`article`
controller
in the
`admin`
subdirectory under the
[
[yii\base\Application::controllerNamespace|controller namespace
]
].
Valid characters for subdirectory prefixes include: English letters in lower and upper cases, digits, underscores and
forward slashes, where forward slashes are used as separators for multi-level subdirectories (e.g.
`panels/admin`
).
### Controller Class Naming <a name="controller-class-naming"></a>
...
...
@@ -134,7 +136,8 @@ takes the default value `app\controllers`:
*
`article`
derives
`app\controllers\ArticleController`
;
*
`post-comment`
derives
`app\controllers\PostCommentController`
;
*
`admin/post2-comment`
derives
`app\controllers\admin\Post2CommentController`
.
*
`admin/post-comment`
derives
`app\controllers\admin\PostCommentController`
;
*
`adminPanels/post-comment`
derives
`app\controllers\adminPanels\PostCommentController`
.
Controller classes must be
[
autoloadable
](
concept-autoloading.md
)
. For this reason, in the above examples,
the
`article`
controller class should be saved in the file whose
[
alias
](
concept-aliases.md
)
...
...
framework/CHANGELOG.md
View file @
390a6c78
...
...
@@ -69,6 +69,7 @@ Yii Framework 2 Change Log
-
Bug #4241:
`yii\widgets\Pjax`
was incorrectly setting container id (mitalcoi)
-
Bug #4276: Added check for UPLOAD_ERR_NO_FILE in
`yii\web\UploadedFile`
and return null if no file was uploaded (OmgDef)
-
Bug #4342: mssql (dblib) driver does not support getting attributes (tof06)
-
Bug #4409: Upper case letters in subdirectory prefixes of controller IDs were not properly handled (qiangxue)
-
Bug: Fixed inconsistent return of
`\yii\console\Application::runAction()`
(samdark)
-
Bug: URL encoding for the route parameter added to
`\yii\web\UrlManager`
(klimov-paul)
-
Bug: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue)
...
...
framework/base/Module.php
View file @
390a6c78
...
...
@@ -548,10 +548,6 @@ class Module extends ServiceLocator
*/
public
function
createControllerByID
(
$id
)
{
if
(
!
preg_match
(
'%^[a-z0-9\\-_/]+$%'
,
$id
))
{
return
null
;
}
$pos
=
strrpos
(
$id
,
'/'
);
if
(
$pos
===
false
)
{
$prefix
=
''
;
...
...
@@ -561,6 +557,13 @@ class Module extends ServiceLocator
$className
=
substr
(
$id
,
$pos
+
1
);
}
if
(
!
preg_match
(
'%^[a-z][a-z0-9\\-_]*$%'
,
$className
))
{
return
null
;
}
if
(
$prefix
!==
''
&&
!
preg_match
(
'%^[a-z0-9_/]+$%i'
,
$prefix
))
{
return
null
;
}
$className
=
str_replace
(
' '
,
''
,
ucwords
(
str_replace
(
'-'
,
' '
,
$className
)))
.
'Controller'
;
$className
=
ltrim
(
$this
->
controllerNamespace
.
'\\'
.
str_replace
(
'/'
,
'\\'
,
$prefix
)
.
$className
,
'\\'
);
if
(
strpos
(
$className
,
'-'
)
!==
false
||
!
class_exists
(
$className
))
{
...
...
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