What Yii2 framework really is?

Yii2 is a powerful full-stack PHP framework for Web Application and Console Application development. It encourages clean code, DRY solutions, event based programming, convention over configuration and modular design. It has a growing library of widgets and extensions, that benefit Rapid Application Development.

Yii2 is easy to learn using the online documentation and wiki. There are many questions and answers on stackoverflow and in the issue tracker on GitHub. It has great performance of the box thanks to lazy loading – components are loaded only if and when they are required. You can further increase performance by extensive use of various caching techniques.

It’s great for getting a small project up and running in no time using the basic or advanced template. Mid size projects are easy to manage by splitting the functionality into multiple modules. Install Yii2 using Composer or an archive.

Yii2 Features

MVC

ActiveRecord models can handle your data, twig or smarty can handle your views or you can use PHP templates. A thin controller is a good controller.

public function actionIndex()
{
    return $this->render('index');
}

ActiveRecord

Working with relational data has never been easier. You can even create relations across different database types (e.g. MySQL and MongoDB).

$post = Post::findOne($id)->with('comments');

Authentication and Authorization

Yii2 advanced template provides signup, login and password reset functionality out of the box. Role Based Access Control is available for advanced authorization schemes.

if (!\Yii::$app->user->isGuest) {
    return $this->goHome();
}

Validation

Use standard validators or create your own.

[['title'], 'string', 'max' => 32]

Forms

Build and customize forms with ease. Use client side validation or AJAX validation.

<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'rememberMe')->checkbox() ?>

Security

XSS prevention, CSRF prevention, protection against brute-force attacks. Bind your parameters and you’ll never have to worry about SQL Injections again. Yii2 will choose the best hashing algorithm available on your server and generate a strong salt, if needed, for you.

Yii::$app->security->validatePassword($password, $this->password_hash);

Internationalization (I18N) and Localization (L10N)

Build multilingual applications easily.

echo \Yii::t('app', 'This string will be translated!');

Caching

Yii2 provides data caching, fragment caching, page caching, HTTP caching, database schema caching.

Code generation

Gii can generate Models for your database tables, Controllers, CRUD for your models, Forms, Modules and Extensions all from a web interface.

Debugger

Yii2 Debugger provides information about your applications and your servers configuration, request data, logs, performance profiling, executed database queries and more. It comes with a great toolbar, that displays the most relevant data.

yii2-debug-toolbar

Many widgets, helpers, extensions

Check out extensions built by others and make your own.

Official Yii2 Extensions

These extensions are supported by the core developers.

apidoc API documentation generator.

authclient OpenID, OAuth and OAuth2.

bootstrap¹ Twitter Bootstrap.

codeception¹ Codeception integration.

composer Composer installer.

debug¹ Debugger for Yii2 applications.

elasticsearch Elasticsearch integration.

faker¹ Faker fixture command.

gii¹ Web-based code generator.

imagine Imagine wrapper.

jui JQuery UI widgets.

mongodb MongoDB integration.

redis redis key-value store support.

smarty  Smarty view template engine.

sphinx Sphinx full text search engine.

swiftmailer¹ SwiftMailer mail solution.

twig Twig view template engine.

¹Part of the basic and advanced yii2 application templates.

You too can contribute to Yii on GitHub by submitting an issue or making a pull request.

Published by

Alexander

Your friendly, neighborhood, full stack, pseudorandom text generator

Leave a Reply