The Definitive Guide to Yii 2.0
This tutorial is released under the Terms of Yii Documentation.
All Rights Reserved.
2014 (c) Yii Software LLC.
- Getting Started
- Application Structure
- Handling Requests
- Key Concepts
- Working with Databases
- Getting Data from Users
- Displaying Data
- RESTful Web Services
- Development Tools
- Special Topics
Active Record provides an object-oriented interface for accessing and manipulating data stored in databases. An Active Record class is associated with a database table, an Active Record instance corresponds to a row of that table, and an attribute of an Active Record instance represents the value of a particular column in that row. Instead of writing raw SQL statements, you would access Active Record attributes and call Active Record methods to access and manipulate the data stored in database tables.
Built on top of Database Access Objects, query builder allows you to construct a SQL query in a programmatic and DBMS-agnostic way. Compared to writing raw SQL statements, using query builder will help you write more readable SQL-related code and generate more secure SQL statements.
Database Access Objects
Built on top of PDO, Yii DAO (Database Access Objects) provides an object-oriented API for accessing relational databases. It is the foundation for other more advanced database access methods, including query builder and active record.
When using Yii DAO, you mainly need to deal with plain SQLs and PHP arrays. As a result, it is the most efficient way to access databases. However, because SQL syntax may vary for different databases, using Yii DAO also means you have to take extra effort to create a database-agnostic application.
Dependency Injection Container
A dependency injection (DI) container is an object that knows how to instantiate and configure objects and all their dependent objects. Martin Fowler's article has well explained why DI container is useful. Here we will mainly explain the usage of the DI container provided by Yii.
A service locator is an object that knows how to provide all sorts of services (or components) that an application might need. Within a service locator, each component exists as only a single instance, uniquely identified by an ID. You use the ID to retrieve a component from the service locator.
In Yii, a service locator is simply an instance of [[yii\di\ServiceLocator]] or a child class.
Yii relies on the class autoloading mechanism to locate and include all required class files. It provides a high-performance class autoloader that is compliant with the PSR-4 standard. The autoloader is installed when you include the
Introduction Article Count: 2
Getting Started Article Count: 8
Application Structure Article Count: 12
Handling Requests Article Count: 8
Key Concepts Article Count: 9
Working with Databases Article Count: 8
Getting Data from Users Article Count: 6
Displaying Data Article Count: 7
Security Article Count: 7
Caching Article Count: 5
RESTful Web Services Article Count: 9
Development Tools Article Count: 3
Testing Article Count: 6
Special Topics Article Count: 12
Widgets Article Count: 2
Helpers Article Count: 4
Page 12 of 18