
Discover how the Yii 2 framework enables rapid, maintainable PHP web applications through MVC, active record, routing, forms, security, REST web services, and official extensions.
Install the Yii 2 framework via composer, configure the database, and explore basic vs. advanced templates, the dependency injection container, and external code such as Zend Framework and Symfony.
Explore how a dependency injection container enables low-coupling design by injecting abstractions into high-level code. Build a shopping cart using a storage interface and session storage wired by the container.
Generate code with g to scaffold models, controllers, and CRUD views from a film table, then configure the database, run the server, and review automatically created relations and rules.
Explore how Yii 2 events work: trigger active record after insert to notify followers when a new article is saved, using custom events and email notifications.
Learn to integrate external code in Yii 2 by installing libraries with composer or manually, configure autoloading and aliases, and use PSR standards to manage components with the composer autoloader.
Learn to use regular expressions in URL rules with the euro router, create apps with the composer package manager, and configure Apache mod_rewrite and .htaccess for parameter rules and 404s.
Learn how to implement a base controller in Yii 2, extend it with derived controllers, and enforce login-based access using an action map.
Learn to use standalone actions in Yii 2 to modularize CRUD operations. Create separate create, delete, index, and view actions as classes and connect them to controllers.
Learn to create a custom filter in Yii 2 that runs before and after actions, applying pre and post logic for access control and content compression, with time-based examples.
Learn to use flash messages in Yii 2 to show success or error notices after form edits or redirects. Messages are stored in the session and cleared after display.
Use the controller context within a view in Yii 2 to access the current controller's methods and properties, such as the page title, and explore rendering partials and widgets.
Learn how to use blocks in Yii 2 to define layout regions, record and render reusable view output with begin block and block from the controller, and conditionally display blocks.
Decorate view output by wrapping content in a decorator template, automatically using the main layout via the render method, and pass extra variables to the decorator for dynamic formatting.
Customize the active query class by default, override the active record find method to return your customized query, and generate a post query class when creating the model.
Process model fields with AR event-like methods in Yii 2 PHP. Preprocess fields before saving or retrieving, using a regex and the parent Active Record implementation.
Enable blameable behavior in Yii 2 to automatically populate created_by and updated_by on model creation and updates. Apply it to a blog_post model and test population of created_by and updated_by.
Set up automatic slugs for blog posts by configuring models and routes with the sluggable behavior to create immutable, unique, user-friendly, search engine friendly urls.
Configure master-slave replication in Yii 2 to route writes to the master and reads to slaves, with load balancing and failover between replicas.
Write and use ad hoc validators in yii 2 by creating a standalone validator, applying it to an article model, and validating success and failure with the validation controller.
Learn to upload files in Yii 2 by building a zip-only uploader with a form, model, and controller, validating with a zip-only file validator and storing in uploads.
Add and customize a captcha widget in Yii 2 PHP, creating a model, controller, and view to generate and validate a verification code and protect against spam.
Customize captcha by replacing text with an arithmetic expression puzzle that uses a random number between 1 and 10, rendering the expression and validating the user's answer to deter spam.
Create a custom range input widget in Yii 2, including widget, controller, model, and view, and enforce first value is less than or equal to second with bootstrap wrappers.
Learn to handle tabular input by using model load multiple and validate multiple to save and validate a contest and its prizes in a single form.
Learn how to collect user input with multiple models in a single complex form, linking user, order, and product data, and validate the submission.
Validate a Yii 2 form with ajax, performing server-side checks for unique company names or emails, and return validation errors in JSON without leaving the page.
Learn how to implement authentication in Yii 2, set up a database-backed login, create a user table and migrations, store password hashes, and extend the user model with identifying interface.
Learn to prevent xss in Yii 2 by escaping dynamic data with the Html helper and HTML purifier, and understand non-persistent and persistent injections to securely encode outputs.
Prevent sql injections in Yii 2 by replacing vulnerable code with prepared statements and parameter binding. Learn how input filtering, white-listing, and secure active record usage defend against attacks.
Learn to prevent CSRF in Yii 2 by implementing unique form tokens, generating and verifying them, and ensuring form submissions originate from the same application using get and post correctly.
Explore rbac in yii 2 by modeling a hierarchical graph of roles, permissions, and rules, and validate access with console commands, migrations, and permission tests.
Learn to encrypt and decrypt data in a Yii 2 PHP app using the framework's security component, active record events, and key derivation for secure storage.
Learn to build a rest server in Yii 2 by creating a minimal restful API for films with an active controller, migrations, and content negotiation.
Set up the authentication model and a new Yii 2 REST app with composer, enabling HTTP basic authentication for endpoints and testing with 401 and 200 responses.
Implement api rate limiting in yii 2 by capping user requests to five per minute and returning too many requests with rate limit headers.
Learn how to version a Yii 2 API using module-based versions V-1 and V-2, enabling two delivery paths via URL prefix or HTTP headers, with independent controllers for each version.
Learn to customize the default error response format in Yii 2 by including a time stamp and a success flag, and test with console commands that yield a 404 error.
Learn to authenticate a client in Yii 2 by installing the official OpenID and OAuth extension, registering an application, obtaining a client id and secret, and configuring the web setup.
Discover how the Yii 2 framework enables fast, secure web applications with PHP, covering configuration, extensions, performance tuning, deployment, testing, logging, and error handling.
Explore the pjax jquery plugin to load content via ajax within widgets, using the HTML5 history API and render partial content with ajax updates and unique widget IDs.
Explore the Redis database driver for Yii 2, enabling Redis key-value storage, cache and session handlers, and an Active Record style access layer with low-level commands and configuration guidance.
Create a Yii 2 model behavior for soft delete and restore, with test-driven development. Attach the behavior to the post model and verify markdown to HTML processing via unit tests.
Create and attach reusable Yii 2 components to an application, fetch currency rates via http json from fixer.io, and override core components for customization.
Create reusable controllers to centralize common code and clear temporary directories, flash cache data, and asset caches, via the controller map in web.php and runtime path settings.
Create a reusable Yii 2 widget to render a pie chart using the Google Charts API, configurable by title, dataset, and data labels.
Create an access filter in Yii 2 to reveal private content after user accepts agreement. Attach it to actions with only or except; redirect to agreement page if cookie missing.
Create a Yii 2 modules log viewer, configure log paths, build log directory and models, and set up a controller to render log entries in a grid view.
Learn how to build a multilanguage Yii 2 application by configuring i18n, creating translation files, and switching languages at runtime with language loaders, cookies, and URL prefixes.
Learn how to prepare Yii 2 extensions for distribution by building a consistent API, clear documentation, well-tested code, PSR standards, semantic versioning, and publishing them to the community.
Learn how to configure Yii 2 for maximum performance by enabling cache components, schema caching, and production settings, while applying best practices for responsive applications and efficient database usage.
Learn to apply full page cache with dependency chaining in Yii 2, using DP and tag dependencies to refresh on article updates, while preserving performance with minimal code changes.
Profile a Yii 2 PHP application to locate bottlenecks, test and profile code with the debug module, and interpret the profiling report to optimize queries and related models loading.
Learn how to implement full page caching in Yii 2 using last-modified and e-tag headers, enabling 200 and not modified responses to optimize page delivery.
Combine and minimize css and javascript assets to reduce http requests, generate compressed bundles in production mode, and configure asset manager with yui compressor to publish and serve bundled assets.
Move application webroot by placing files in the root or a subdirectory, rename the web directory to public_html, with the app automatically setting webroot alias paths from the entry script.
Use multiple configurations to simplify deployments with an advanced configuration system in yii 2 php templates, merging common and application properties from separate config files and managing environments.
Implement cron jobs in Yii 2 by creating a console command, scheduling it with cron, and writing the current timestamp to a protected directory's timestamp.txt.
Explore testing a Yii 2 application with Codeception, PHPUnit, and related tools, covering unit, functional, and acceptance tests, along with migrations, fixtures, code coverage, and API testing.
Learn unit testing with atoum in PHP by building a shopping cart extension, configuring composer, and implementing a storage interface for isolated tests.
Configure and use different log routes to route messages by level and category, including email for errors, a stack trace, file and database targets, and profiling for debugging.
analyze the error stack trace to identify the root cause, learn how to read the first expanded section and alias usage, and prepare for logging and context information.
Configure the logger in Yii 2 PHP app to capture the execution context, write errors to a file, and inspect logs including GET, POST variables, SQL, and server variables.
Learn to design a custom panel for the Yii 2 debug extension in PHP, including creating the panel, views, and toolbar configuration, with data handling and error logging.
Explore building high-load web applications with the Yii 2 framework, using Bootstrap for responsiveness, security and access control, encryption, caching, session storage, config tweaks, and Codeception testing.
Create a local git repository, make the initial commit, push updates to a bitbucket remote, and pull others' changes to keep the load project synchronized.
Automate deployments by configuring Bitbucket hooks and a deploy script on your VPS, set up webhooks, clone your repo, and test automatic updates via commits and pushes.
Discover how to add bootstrap components to a high-load web page, including icons, button groups, and labels, and customize colors and sizes for responsive design.
Learn to embed Bootstrap JavaScript features, including modal windows and popovers, into a home page using a few lines of code and data-toggle and data-target attributes.
Escape and sanitize user input, and encode output to prevent XSS. Protect form submissions with csrf protection and tokens by default.
Explore how caching boosts performance in high-load Yii 2 apps by storing recently generated data, per-user caches, and fragment or full page caching, plus database query caching.
Configure asset components to combine and compress JavaScript and CSS files for high-load front-ends, using asset manager, production builds, and tools like closure compiler and YUI compressor.
Learn how to move sessions and cache storage to a database in a Yii 2 PHP app, enabling shared, scalable storage for high-load front-end servers.
Switch cache and session storage to memcached to speed up requests and enable sharing across front-end servers, reducing database queries to zero in the Yii 2 framework.
Learn how to use Redis for session and cache storage in a high-load Yii 2 PHP application, including installation with composer, configuration of cache and session components, and performance considerations.
Learn how to use Sphinx for fast full text search in a Yii 2 app, install two components, index a post table, and perform quick searches that reduce database load.
Install and configure Elasticsearch for a Yii 2 application, index posts into Elasticsearch storage, and perform fast full text search using the classic search service.
Learn to implement full text search with MongoDB storage in a Yii 2 app, replacing elastic search, configure MongoDB components, update the post model, load data, and test fast search.
Install and configure codeception and the php testing framework to automate unit and functional tests for a Yii 2 application, including front-end tests and database setup.
Explore functional testing with Codeception alongside unit and acceptance tests in a Yii 2 PHP app, including sign-up validation and a post index page test.
Are you a PHP developer working on Yii framework? Do you want explore the new features of Yii 2 for creating fast-paced, secured web 2.0 based applications? If yes, this Learning Path is for you.
Yii is a high-performance, component-based PHP framework for rapidly developing modern web applications. The name Yii can be considered as the acronym for Yes It Is!. Yii 2 inherits the main spirit behind Yii for being a simple, fast, highly-extensible PHP framework.
Packt’s Video Learning Paths are a series of individual video products put together in a logical and stepwise manner such that video builds on the skills learned in the video before it.
This Learning Path begins with installing Yii 2 framework, learning about application templates, dependency injection container, and model events. Then, you’ll learn to use your external code along with updating your existing Yii 1 applications to Yii 2. Also, you’ll be familiar with some main methods for working with databases in Yii 2, such as Active Record, Query Builder, and direct SQL queries through DAO. Next, you’ll learn to write RESTful Web Services using Yii 2. Further, you’ll learn to deploy and test your applications securely with introduction to some best technologies, such as Codeception, PHPUnit, Atoum, and Behat. As the Learning Path progresses, you’ll be introduced to Git and its most used commands to work smoothly in a distributed team. You’ll also learn to develop customized and reliable web applications along with making these applications responsive using Twitter Bootstrap framework. Finally, you’ll learn to secure your applications by encrypting and decrypting data using Yii 2 components.
By the end of this Learning Path, you will have a deep understanding of the new and advanced features and concepts introduced in Yii 2 framework and application development practices using it.
About the Authors:
For this course, we have combined the best works of these esteemed authors:
Alexander Makarov is an experienced engineer from Russia and has been an Yii framework core team member since 2010. Before joining the Yii core team, he participated in the growth of the CodeIgniter community in Russia. . He has been a technical reviewer for books on Yii as well.
Dmitry Eliseev has been a web developer since 2008 and specializes in server-side programming on the PHP and PHP frameworks. Since 2012, he has authorized his personal blog, about web development in general and about the Yii framework in particular. His blog has become a well-known resource in the Russian Yii community.
Andrew Bogdanov is a seasoned web developer from Yekaterinburg, Russia with more than six years of experience in industrial development. Since 2010 he has been interested in the Yii and MVC frameworks. He has worked on various CMS and frameworks using PHP and MySQL, including Yii, Kohana, Symphony, Joomla, WordPress, CakePHP, and so on. He is very good in slicing and frontend, so he can provide full information about the Yii framework.
Vitalii Tron has about 7 years of experience in programming and he has been developing Yii-based applications for 4 years. He graduated from the Sumy State University in the Mechanical-Mathematics School of Computer Science department. He also successfully finished post-graduate courses at the same department. Vitalii has amazing job history at Elance, where his clients have left delighted feedback about his work.