http://bit.ly/2Sh503b
Qiang Xue,
Alexander Makarov,
Carsten Brandt,
Klimov Paul,
]
many contributors from the Yii community
Spanish translation provided by:
Antonio Ramirez,
Daniel Gómez Pan,
'larnu',
Luciano Baraglia
This tutorial is released under the Terms of Yii Documentation.
Copyright 2014 Yii Software LLC. All Rights Reserved.
Índice general
1. Introduction
1.1. What is Yii? . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2. Update from Yii 1.1. . . . . . . . . . . . . . . . . . . . .
2. First steps
Install Yii
2.1.
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2. Running Applications. . . . . . . . . . . . . . . . . . . . . .
2.3. Saying hello . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4. Working with Forms . . . . . . . . . . . . . . . . .
2.5. Work with Databases
. . . . . . . . . . . . . . . . . .
2.6. Generating Code with Gii. . . . . . . . . . . . . . . . . . . .
2.7. Looking forward . . . . . . . . . . . . . . . . . . . .
1
1
2
15
15
20
25
28
33
39
45
3. Structure of an application
47
47
3.1.
General information. . . . . . . . . . . . . . . . . . . . . . .
48
3.2. Input Scripts . . . . . . . . . . . . . . . . . . . . . . .
50
3.3. Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . .
62
3.4. Components of the Application . . . . . . . . . . . . . . . . .
64
3.5. Drivers. . . . . . . . . . . . . . . . . . . . . . . . . . .
74
3.6. Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
84
3.7. Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.8. Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
99
3.9. Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
3.10. Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
3.11. Assets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
3.12. Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
4. Management of petitions
General Information
143
4.1.
. . . . . . . . . . . . . . . . . . . . . . . 143
4.2. Bootstrapping. . . . . . . . . . . . . . . . . . . . . . . . . . . 144
4.3. Routing and URLS creation. . . . . . . . . . . . . . . 145
4.4. Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
4.5. Answers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
iii
iv
GENERAL INDEX
4.6. Sessions (Sessions) and Cookies
. . . . . . . . . . . . . . . . . . 168
4.7. Error Management . . . . . . . . . . . . . . . . . . . . . . . 175
4.8. Record of annotations
. . . . . . . . . . . . . . . . . . . . . 179
5. Key concepts
189
5.1. Components . . . . . . . . . . . . . . . . . . . . . . . . . . 189
5.2. Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
5.3. Events
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
5.4. Behaviors . . . . . . . . . . . . . . . . . . . . . . . . 199
5.5. Con fi guration . . . . . . . . . . . . . . . . . . . . . . . . . . 205
5.6. Alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
5.7. Self-loading of classes. . . . . . . . . . . . . . . . . . . . . . . . 213
5.8. Service Locator. . . . . . . . . . . . . . . . . . . . . 215
5.9. Dependency Injection Container. . . . . . . . . . . 217
6. Work with databases
225
. . . . . . . . . . . . . . 225
6.1. Access Objects to Databases
6.2. Consultant Builder
. . . . . . . . . . . . . . . . . . . . 237
6.3. Migration of Database. . . . . . . . . . . . . . . . . . . 248
7. Obtain data from users
271
7.1. Input Validation . . . . . . . . . . . . . . . . . . . . . 273
7.2. Upload Files
. . . . . . . . . . . . . . . . . . . . . . . . . . 287
7.3. Obtaining data for multiple models. . . . . . . 293
8. Visualize data
295
8.1. Pagination . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
8.2. Work with Client Scripts . . . . . . . . . . . . . . . . 302
8.3. Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
9. Security
307
9.1. Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
9.2. Work with Passwords
. . . . . . . . . . . . . . . . . . . . . 324
10.Caché
329
10.1. Caching . . . . . . . . . . . . . . . . . 329
10.2. Data Storage in Caché
. . . . . . . . . . . . . . 329
10.3. Fragment cache. . . . . . . . . . . . . . . . . . . . . . . 338
10.4. Cache of Pages. . . . . . . . . . . . . . . . . . . . . . . . . 342
10.5. HTTP cache . . . . . . . . . . . . . . . . . . . . . . . . . . 343
11. RESTful Web Services
347
11.1. Brief Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
11.2. Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
11.3. Drivers. . . . . . . . . . . . . . . . . . . . . . . . . . . 356
GENERAL INDEX
v
11.4. Routing . . . . . . . . . . . . . . . . . . . . . . . . . . 359
11.5. Response format. . . . . . . . . . . . . . . . . . . . . . 361
11.6. Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . 364
11.7. Limiting the range (rate)
. . . . . . . . . . . . . . . . . . . . 367
11.8. Versioned . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
11.9. Error handling . . . . . . . . . . . . . . . . . . . . . . . . 371
12. Development Tools
375
13. Tests
379
13.1. Preparation of the test environment. . . . . . . . . . . . . . . . . 381
13.2. Unit Tests. . . . . . . . . . . . . . . . . . . . . . . . . 382
13.3. Functional Tests . . . . . . . . . . . . . . . . . . . . . . . . 382
13.4. Fixtures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
13.5. Manage Fixtures. . . . . . . . . . . . . . . . . . . . . . . 389
14. Special topics
393
14.1. Create your own Application structure. . . . . . . . . . . . 395
14.2. Validators of the framework. . . . . . . . . . . . . . . . . . . . 398
14.3. Sending of Emails
. . . . . . . . . . . . . . . . . . . . . . . . . 411
14.4. Use template engines . . . . . . . . . . . . . . . . . . . 418
14.5. Work with third-party code. . . . . . . . . . . . . . . . . 419
15.Widgets
423
16.Assistant classes
427
16.1. Helpers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
16.2. ArrayHelper . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
. . . . . . . . . . . . . . . 436
16.3. Html helper class (Html helper)
16.4. Auxiliary Class URL (URL Helper)
. . . . . . . . . . . . . . . 443
vi
GENERAL INDEX
Chapter 1
Introduction
1.1.
What is Yii?
Yii is a high performance PHP framework based on components
] to develop modern web applications in a short time. The name Yii
means "simple and evolutionary" in Chinese. It can also be considered as
an acronym for Yes It Is (which in English means Yes, that is)!
1.1.1.
What is better Yii?
Yii is a generic framework of web programming, which means that
can be used to develop all kinds of web applications in PHP. Because of
its component-based architecture and its sophisticated cache compatibility
it is especially appropriate for the development of large
applications, such as portals, forums, content management systems
(CMS ), e-commerce projects, web services compatible with the
REST architecture and many more.
1.1.2.
How does Yii compare with other frameworks?
If you are familiar with other frameworks, you can appreciate how it is com-
for Yii with them:
Like most PHP frameworks, Yii implements the pattern of
MVC design (Model-View-Controller) and promotes organization
of code based on this pattern.
The philosophy of Yii is to write the code in a simple way and
elegant, without overdesigning by the mere fact of following a pattern
of a certain design.
Yii it's a complete framework This provides many features that are
badas and ready to use, such as query builders and class
ActiveRecord for relational databases and NoSQL, the company
1
2 [19659002] CHAPTER 1. INTRODUCTION
ability to use the REST architecture to develop the API, the compatibility
cache in several levels and many more.
Yii is extremely extensible. You can customize or replace
practically any piece of basic code, as you can also
well take advantage of its robust extensions architecture to use or
develop distributable extensions.
High performance is always the goal principal of Yii.
Yii is not a one-person project, behind Yii there is a solid team of
development1, as well as a large community in which numerous professionals
constantly contribute to its development. The Yii development team
keeps an eye on the latest web development trends, as well as
on the best practices and features of other frameworks and projects.
Best practices and most relevant characteristics of other projects
is regularly incorporated into the base of the framework and is exposed through
simple and elegant interfaces.
1.1.3. Versions of Yii
There are currently two major versions of Yii: version 1.1 and
version 2.0. For version 1.1, which is from the previous generation, currently
only maintenance is offered. Version 2.0 is completely rewritten
and adopts the latest technologies and protocols, including Composer, PSR,
namespaces, traits, etc. Version 2.0 represents the current generation of the
framework and its development will receive the main effort in the coming years.
This guide is based mainly on version 2.0. of the framework.
1.1.4. Requirements
Yii 2.0 requires PHP 5.4.0 or a version
from Nettech Post http://bit.ly/2Ae5Sia
No hay comentarios:
Publicar un comentario