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
4dedd5aa
Commit
4dedd5aa
authored
May 30, 2014
by
artur
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:yiisoft/yii2
parents
d2fcbcc0
d7a251bb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
150 additions
and
86 deletions
+150
-86
AppController.php
build/controllers/AppController.php
+6
-2
README.md
docs/guide/README.md
+4
-2
structure-application-components.md
docs/guide/structure-application-components.md
+93
-0
structure-applications.md
docs/guide/structure-applications.md
+3
-68
structure-controllers.md
docs/guide/structure-controllers.md
+0
-0
structure-filters.md
docs/guide/structure-filters.md
+42
-0
ApiIndexer.php
extensions/apidoc/helpers/ApiIndexer.php
+0
-1
ApiMarkdown.php
extensions/apidoc/helpers/ApiMarkdown.php
+0
-1
ApiMarkdownTrait.php
extensions/apidoc/helpers/ApiMarkdownTrait.php
+0
-1
GuideRenderer.php
extensions/apidoc/templates/pdf/GuideRenderer.php
+0
-2
ActiveQuery.php
extensions/elasticsearch/ActiveQuery.php
+0
-1
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Controller.php
framework/base/Controller.php
+1
-1
AssetController.php
framework/console/controllers/AssetController.php
+0
-1
BaseVarDumper.php
framework/helpers/BaseVarDumper.php
+0
-2
CreateAction.php
framework/rest/CreateAction.php
+0
-1
DeleteAction.php
framework/rest/DeleteAction.php
+0
-1
VarDumperTest.php
tests/unit/framework/helpers/VarDumperTest.php
+0
-1
DbManagerTestCase.php
tests/unit/framework/rbac/DbManagerTestCase.php
+0
-1
No files found.
build/controllers/AppController.php
View file @
4dedd5aa
...
...
@@ -8,9 +8,7 @@
namespace
yii\build\controllers
;
use
Yii
;
use
yii\base\InvalidParamException
;
use
yii\console\Controller
;
use
yii\helpers\Console
;
use
yii\helpers\FileHelper
;
/**
...
...
@@ -77,6 +75,12 @@ class AppController extends Controller
$this
->
stdout
(
"done.
\n
"
);
}
/**
* Finds linkable applications
*
* @param string $dir directory to search in
* @return array list of applications command can link
*/
protected
function
findDirs
(
$dir
)
{
$list
=
[];
...
...
docs/guide/README.md
View file @
4dedd5aa
...
...
@@ -32,9 +32,11 @@ Application Structure
*
[
Entry Scripts
](
structure-entry-scripts.md
)
*
[
Applications
](
structure-applications.md
)
*
[
Controllers and Actions
](
structure-controllers.md
)
*
[
Application Components
](
structure-application-components.md
)
*
[
Controllers
](
structure-controllers.md
)
*
[
Views
](
structure-views.md
)
*
[
Models
](
structure-models.md
)
*
**TBD**
[
Filters
](
structure-filters.md
)
*
**TBD**
[
Widgets
](
structure-widgets.md
)
*
**TBD**
[
Modules
](
structure-modules.md
)
*
**TBD**
[
Extensions
](
structure-extensions.md
)
...
...
@@ -49,7 +51,7 @@ Handling Requests
*
**TBD**
[
Responses
](
runtime-responses.md
)
*
**TBD**
[
Sessions and Cookies
](
runtime-sessions-cookies.md
)
*
[
URL Parsing and Generation
](
runtime-url-handling.md
)
*
**TBD**
[
Filtering
](
runtime-filtering.md
)
Key Concepts
...
...
docs/guide/structure-application-components.md
0 → 100644
View file @
4dedd5aa
Application Components
======================
Applications are
[
service locators
](
concept-service-locators.md
)
. They host a set of the so-called
*application components*
that provide different services for processing requests. For example,
the
`urlManager`
component is responsible for routing Web requests to appropriate controllers;
the
`db`
component provides DB-related services; and so on.
Each application component has an ID that uniquely identifies itself among other application components
in the same application. You can access an application component through the expression
```
php
\Yii
::
$app
->
ComponentID
```
For example, you can use
`\Yii::$app->db`
to get the
[
[yii\db\Connection|DB connection
]
],
and
`\Yii::$app->cache`
to get the
[
[yii\caching\Cache|primary cache
]
] registered with the application.
Application components can be any objects. You can register them by configuring
the
[
[yii\base\Application::components
]
] property in
[
application configurations
](
structure-applications.md#application-configurations
)
.
For example,
```
php
[
'components'
=>
[
// register "cache" component using a class name
'cache'
=>
'yii\caching\ApcCache'
,
// register "db" component using a configuration array
'db'
=>
[
'class'
=>
'yii\db\Connection'
,
'dsn'
=>
'mysql:host=localhost;dbname=demo'
,
'username'
=>
'root'
,
'password'
=>
''
,
],
// register "search" component using an anonymous function
'search'
=>
function
()
{
return
new
app\components\SolrService
;
},
],
]
```
> Info: While you can register as many application components as you want, you should do this judiciously.
Application components are like global variables. Using too many application components can potentially
make your code harder to test and maintain. In many cases, you can simply create a local component
and use it when needed.
## Core Application Components <a name="core-application-components"></a>
Yii defines a set of
*core*
application components with fixed IDs and default configurations. For example,
the
[
[yii\web\Application::request|request
]
] component is used to collect information about
a user request and resolve it into a
[
route
](
runtime-routing.md
)
; the
[
[yii\base\Application::db|db
]
]
component represents a database connection through which you can perform database queries.
It is with help of these core application components that Yii applications are able to handle user requests.
Below is the list of the predefined core application components. You may configure and customize them
like you do with normal application components. When you are configuring a core application component,
if you do not specify its class, the default one will be used.
*
[
[yii\web\AssetManager|assetManager
]
]: manages asset bundles and asset publishing.
Please refer to the
[
Managing Assets
](
output-assets.md
)
section for more details.
*
[
[yii\db\Connection|db
]
]: represents a database connection through which you can perform DB queries.
Note that when you configure this component, you must specify the component class as well as other required
component properties, such as
[
[yii\db\Connection::dsn
]
].
Please refer to the
[
Data Access Objects
](
db-dao.md
)
section for more details.
*
[
[yii\base\Application::errorHandler|errorHandler
]
]: handles PHP errors and exceptions.
Please refer to the
[
Handling Errors
](
tutorial-handling-errors.md
)
section for more details.
*
[
[yii\base\Formatter|formatter
]
]: formats data when they are displayed to end users. For example, a number
may be displayed with thousand separator, a date may be formatted in long format.
Please refer to the
[
Data Formatting
](
output-formatting.md
)
section for more details.
*
[
[yii\i18n\I18N|i18n
]
]: supports message translation and formatting.
Please refer to the
[
Internationalization
](
tutorial-i18n.md
)
section for more details.
*
[
[yii\log\Dispatcher|log
]
]: manages log targets.
Please refer to the
[
Logging
](
tutorial-logging.md
)
section for more details.
*
[
[yii\swiftmailer\Mailer|mail
]
]: supports mail composing and sending.
Please refer to the
[
Mailing
](
tutorial-mailing.md
)
section for more details.
*
[
[yii\base\Application::response|response
]
]: represents the response being sent to end users.
Please refer to the
[
Responses
](
runtime-responses.md
)
section for more details.
*
[
[yii\base\Application::request|request
]
]: represents the request received from end users.
Please refer to the
[
Requests
](
runtime-requests.md
)
section for more details.
*
[
[yii\web\Session|session
]
]: represents the session information. This component is only available
in
[
[yii\web\Application|Web applications
]
].
Please refer to the
[
Sessions and Cookies
](
runtime-sessions-cookies.md
)
section for more details.
*
[
[yii\web\UrlManager|urlManager
]
]: supports URL parsing and creation.
Please refer to the
[
URL Parsing and Generation
](
runtime-url-handling.md
)
section for more details.
*
[
[yii\web\User|user
]
]: represents the user authentication information. This component is only available
in
[
[yii\web\Application|Web applications
]
]
Please refer to the
[
Authentication
](
security-authentication.md
)
section for more details.
*
[
[yii\web\View|view
]
]: supports view rendering.
Please refer to the
[
Views
](
structure-views.md
)
section for more details.
docs/guide/structure-applications.md
View file @
4dedd5aa
...
...
@@ -177,7 +177,7 @@ The rest of the array elements (key-value pairs) specify the parameters to be bo
#### [[yii\base\Application::components|components]] <a name="components"></a>
This is the single most important property. It allows you to register a list of named components
called
[
application components
](
#
application-components
)
that you can use in other places. For example,
called
[
application components
](
#
structure-application-components.md
)
that you can use in other places. For example,
```
php
[
...
...
@@ -199,7 +199,7 @@ while the value represents the component class name or [configuration](concept-c
You can register any component with an application, and the component can later be accessed globally
using the expression
`\Yii::$app->ComponentID`
.
Please read the
[
application components
](
#application-components
)
section for details.
Please read the
[
Application Components
](
structure-application-components.md
)
section for details.
#### [[yii\base\Application::controllerMap|controllerMap]] <a name="controllerMap"></a>
...
...
@@ -217,7 +217,7 @@ specific controllers. In the following example, `account` will be mapped to
'account'
=>
'app\controllers\UserController'
,
'article'
=>
[
'class'
=>
'app\controllers\PostController'
,
'
pageTitle'
=>
'something new'
,
'
enableCsrfValidation'
=>
false
,
],
],
],
...
...
@@ -569,71 +569,6 @@ as for that of `beforeAction`. That is, controllers are the first objects trigge
followed by modules (if any), and finally applications.
## Application Components <a name="application-components"></a>
Applications are
[
service locators
](
concept-service-locators.md
)
. They host a set of the so-called
*application components*
that provide different services for processing requests. For example,
the
`urlManager`
component is responsible for routing Web requests to appropriate controllers;
the
`db`
component provides DB-related services; and so on.
Each application component has an ID that uniquely identifies itself among other application components
in the same application. You can access an application component through the expression
`$app->ID`
,
where
`$app`
refers to an application instance, and
`ID`
stands for the ID of an application component.
For example, you can use
`Yii::$app->db`
to get the
[
[yii\db\Connection|DB connection
]
], and
`Yii::$app->cache`
to get the
[
[yii\caching\Cache|primary cache
]
] registered with the application.
Application components can be any objects. You can register them with an application to make them
globally accessible. This is usually done by configuring the
[
[yii\base\Application::components
]
] property,
as described in the
[
components
](
#components
)
subsection.
> Info: While you can register as many application components as you want, you should do this judiciously.
Application components are like global variables. Using too many application components can potentially
make your code harder to test and maintain. In many cases, you can simply create a local component
and use it when needed.
Yii defines a set of
*core*
application components with fixed IDs and default configurations. For example,
the
[
[yii\web\Application::request|request
]
] component is used to collect information about
a user request and resolve it into a
[
route
](
runtime-routing.md
)
; the
[
[yii\base\Application::db|db
]
]
component represents a database connection through which you can perform database queries.
It is with help of these core application components that Yii applications are able to handle user requests.
Below is the list of the predefined core application components. You may configure and customize them
like you do with normal application components. When you are configuring a core application component,
if you do not specify its class, the default one will be used.
*
[
[yii\web\AssetManager|assetManager
]
]: manages asset bundles and asset publishing.
Please refer to the
[
Managing Assets
](
output-assets.md
)
section for more details.
*
[
[yii\db\Connection|db
]
]: represents a database connection through which you can perform DB queries.
Note that when you configure this component, you must specify the component class as well as other required
component properties, such as
[
[yii\db\Connection::dsn
]
].
Please refer to the
[
Data Access Objects
](
db-dao.md
)
section for more details.
*
[
[yii\base\Application::errorHandler|errorHandler
]
]: handles PHP errors and exceptions.
Please refer to the
[
Handling Errors
](
tutorial-handling-errors.md
)
section for more details.
*
[
[yii\base\Formatter|formatter
]
]: formats data when they are displayed to end users. For example, a number
may be displayed with thousand separator, a date may be formatted in long format.
Please refer to the
[
Data Formatting
](
output-formatting.md
)
section for more details.
*
[
[yii\i18n\I18N|i18n
]
]: supports message translation and formatting.
Please refer to the
[
Internationalization
](
tutorial-i18n.md
)
section for more details.
*
[
[yii\log\Dispatcher|log
]
]: manages log targets.
Please refer to the
[
Logging
](
tutorial-logging.md
)
section for more details.
*
[
[yii\swiftmailer\Mailer|mail
]
]: supports mail composing and sending.
Please refer to the
[
Mailing
](
tutorial-mailing.md
)
section for more details.
*
[
[yii\base\Application::response|response
]
]: represents the response being sent to end users.
Please refer to the
[
Responses
](
runtime-responses.md
)
section for more details.
*
[
[yii\base\Application::request|request
]
]: represents the request received from end users.
Please refer to the
[
Requests
](
runtime-requests.md
)
section for more details.
*
[
[yii\web\Session|session
]
]: represents the session information. This component is only available
in
[
[yii\web\Application|Web applications
]
].
Please refer to the
[
Sessions and Cookies
](
runtime-sessions-cookies.md
)
section for more details.
*
[
[yii\web\UrlManager|urlManager
]
]: supports URL parsing and creation.
Please refer to the
[
URL Parsing and Generation
](
runtime-url-handling.md
)
section for more details.
*
[
[yii\web\User|user
]
]: represents the user authentication information. This component is only available
in
[
[yii\web\Application|Web applications
]
]
Please refer to the
[
Authentication
](
security-authentication.md
)
section for more details.
*
[
[yii\web\View|view
]
]: supports view rendering.
Please refer to the
[
Views
](
structure-views.md
)
section for more details.
## Application Lifecycle <a name="application-lifecycle"></a>
When an
[
entry script
](
structure-entry-scripts.md
)
is being executed to handle a request,
...
...
docs/guide/structure-controllers.md
View file @
4dedd5aa
This diff is collapsed.
Click to expand it.
docs/guide/structure-filters.md
0 → 100644
View file @
4dedd5aa
You may apply some action filters to controller actions to accomplish tasks such as determining
who can access the current action, decorating the result of the action, etc.
An action filter is an instance of a class extending
[
[yii\base\ActionFilter
]
].
To use an action filter, attach it as a behavior to a controller or a module. The following
example shows how to enable HTTP caching for the
`index`
action:
```
php
public
function
behaviors
()
{
return
[
'httpCache'
=>
[
'class'
=>
\yii\filters\HttpCache
::
className
(),
'only'
=>
[
'index'
],
'lastModified'
=>
function
(
$action
,
$params
)
{
$q
=
new
\yii\db\Query
();
return
$q
->
from
(
'user'
)
->
max
(
'updated_at'
);
},
],
];
}
```
You may use multiple action filters at the same time. These filters will be applied in the
order they are declared in
`behaviors()`
. If any of the filter cancels the action execution,
the filters after it will be skipped.
When you attach a filter to a controller, it can be applied to all actions of that controller;
If you attach a filter to a module (or application), it can be applied to the actions of any controller
within that module (or application).
To create a new action filter, extend from
[
[yii\base\ActionFilter
]
] and override the
[
[yii\base\ActionFilter::beforeAction()|beforeAction()
]
] and
[
[yii\base\ActionFilter::afterAction()|afterAction()
]
]
methods. The former will be executed before an action runs while the latter after an action runs.
The return value of
[
[yii\base\ActionFilter::beforeAction()|beforeAction()
]
] determines whether
an action should be executed or not. If
`beforeAction()`
of a filter returns false, the filters after this one
will be skipped and the action will not be executed.
The
[
authorization
](
authorization.md
)
section of this guide shows how to use the
[
[yii\filters\AccessControl
]
] filter,
and the
[
caching
](
caching.md
)
section gives more details about the
[
[yii\filters\PageCache
]
] and
[
[yii\filters\HttpCache
]
] filters.
These built-in filters are also good references when you learn to create your own filters.
extensions/apidoc/helpers/ApiIndexer.php
View file @
4dedd5aa
...
...
@@ -11,7 +11,6 @@ namespace yii\apidoc\helpers;
use
cebe\jssearch\Indexer
;
use
cebe\jssearch\tokenizer\StandardTokenizer
;
use
cebe\jssearch\TokenizerInterface
;
use
yii\helpers\StringHelper
;
class
ApiIndexer
extends
Indexer
{
...
...
extensions/apidoc/helpers/ApiMarkdown.php
View file @
4dedd5aa
...
...
@@ -9,7 +9,6 @@ namespace yii\apidoc\helpers;
use
cebe\markdown\GithubMarkdown
;
use
phpDocumentor\Reflection\DocBlock\Type\Collection
;
use
yii\apidoc\models\MethodDoc
;
use
yii\apidoc\models\TypeDoc
;
use
yii\apidoc\renderers\BaseRenderer
;
use
yii\helpers\Inflector
;
...
...
extensions/apidoc/helpers/ApiMarkdownTrait.php
View file @
4dedd5aa
...
...
@@ -8,7 +8,6 @@
namespace
yii\apidoc\helpers
;
use
cebe\markdown\GithubMarkdown
;
use
phpDocumentor\Reflection\DocBlock\Type\Collection
;
use
yii\apidoc\models\MethodDoc
;
use
yii\apidoc\models\TypeDoc
;
...
...
extensions/apidoc/templates/pdf/GuideRenderer.php
View file @
4dedd5aa
...
...
@@ -9,11 +9,9 @@ namespace yii\apidoc\templates\pdf;
use
cebe\markdown\latex\GithubMarkdown
;
use
Yii
;
use
yii\apidoc\helpers\ApiIndexer
;
use
yii\apidoc\helpers\ApiMarkdownLaTeX
;
use
yii\apidoc\helpers\IndexFileAnalyzer
;
use
yii\helpers\Console
;
use
yii\helpers\FileHelper
;
/**
*
...
...
extensions/elasticsearch/ActiveQuery.php
View file @
4dedd5aa
...
...
@@ -7,7 +7,6 @@
namespace
yii\elasticsearch
;
use
yii\base\NotSupportedException
;
use
yii\db\ActiveQueryInterface
;
use
yii\db\ActiveQueryTrait
;
use
yii\db\ActiveRelationTrait
;
...
...
framework/CHANGELOG.md
View file @
4dedd5aa
...
...
@@ -38,6 +38,7 @@ Yii Framework 2 Change Log
-
Bug #3601: Fixed the bug that the refresh URL was not generated correctly by
`Captcha`
(qiangxue, klevron)
-
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)
-
Enh #2264:
`CookieCollection::has()`
will return false for expired or removed cookies (qiangxue)
-
Enh #2435:
`yii\db\IntegrityException`
is now thrown on database integrity errors instead of general
`yii\db\Exception`
(samdark)
-
Enh #2837: Error page now shows arguments in stack trace method calls (samdark)
...
...
framework/base/Controller.php
View file @
4dedd5aa
...
...
@@ -216,7 +216,7 @@ class Controller extends Component implements ViewContextInterface
$methodName
=
'action'
.
str_replace
(
' '
,
''
,
ucwords
(
implode
(
' '
,
explode
(
'-'
,
$id
))));
if
(
method_exists
(
$this
,
$methodName
))
{
$method
=
new
\ReflectionMethod
(
$this
,
$methodName
);
if
(
$method
->
getName
()
===
$methodName
)
{
if
(
$method
->
isPublic
()
&&
$method
->
getName
()
===
$methodName
)
{
return
new
InlineAction
(
$id
,
$this
,
$methodName
);
}
}
...
...
framework/console/controllers/AssetController.php
View file @
4dedd5aa
...
...
@@ -10,7 +10,6 @@ namespace yii\console\controllers;
use
Yii
;
use
yii\console\Exception
;
use
yii\console\Controller
;
use
yii\helpers\StringHelper
;
use
yii\helpers\VarDumper
;
/**
...
...
framework/helpers/BaseVarDumper.php
View file @
4dedd5aa
...
...
@@ -7,8 +7,6 @@
namespace
yii\helpers
;
use
yii\base\Arrayable
;
/**
* BaseVarDumper provides concrete implementation for [[VarDumper]].
*
...
...
framework/rest/CreateAction.php
View file @
4dedd5aa
...
...
@@ -9,7 +9,6 @@ namespace yii\rest;
use
Yii
;
use
yii\base\Model
;
use
yii\db\ActiveRecord
;
use
yii\helpers\Url
;
/**
...
...
framework/rest/DeleteAction.php
View file @
4dedd5aa
...
...
@@ -8,7 +8,6 @@
namespace
yii\rest
;
use
Yii
;
use
yii\db\ActiveRecord
;
/**
* DeleteAction implements the API endpoint for deleting a model.
...
...
tests/unit/framework/helpers/VarDumperTest.php
View file @
4dedd5aa
<?php
namespace
yiiunit\framework\helpers
;
use
yii\data\ArrayDataProvider
;
use
yii\helpers\VarDumper
;
use
yiiunit\TestCase
;
...
...
tests/unit/framework/rbac/DbManagerTestCase.php
View file @
4dedd5aa
...
...
@@ -4,7 +4,6 @@ namespace yiiunit\framework\rbac;
use
Yii
;
use
yii\console\Application
;
use
yii\console\Controller
;
use
yii\console\controllers\MigrateController
;
use
yii\db\Connection
;
use
yii\rbac\DbManager
;
...
...
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