Yii2 :: Active Record

Remarks AR is perfect when you need to delete, update or create one or more records sequentially. Its support of dirty attributes (saving only what was really changed) results in optimized UPDATE statements which lifts the load from database significantly and reduces chances for various conflicts connected with editing same record by multiple persons at … Read more

Yii2 :: SEO essentials

1. Enable pretty URLs Sometimes users want to share your site URLs via social networks.  For example, by default your about page URL looks like http://mkchowdhury.com/index.php?r=site%2Fabout.  Let’s imagine this link on Facebook page. Do you want to click on it? Most of users have no idea what is index.php and what is %2.  They trust … Read more

Yii2 :: Handling incoming third party POST requests

By default Yii uses CSRF protection that verifies that POST requests could be made only by the same application.  It enhances overall security significantly but there are cases when CSRF should be disabled i.e.  when you expect incoming POST requests from a third party service. Additionally, if third party is posting via XMLHttpRequest (browser AJAX), … Read more

Yii2 :: Managing cookies

Managing HTTP cookies isn’t that hard using plain PHP but Yii makes it a bit more convenient. In this recipe we’ll describe how to perform typical cookie actions. 1. Setting a cookie To set a cookie i.e.  to create it and schedule for sending to the browser you need to create new \yii\web\Cookie class instance … Read more

Yii2 :: Working with different response types

Web and mobile applications are more than just rendered HTML nowadays. Modern architecture moves the UI to the client, where all user interactions are handled by the client-side, utilizing server APis to drive the frontend. The JSON and XML formats are often used for serializing and transmitting structured data over a network, so the ability … Read more

Yii2 :: URL with many parameters

There are many cases when you need to get variable number of parameters via URL. For example one may want URL such as http://mkchowdhury.com/product/male/jeans to lead to ProductController: :actionCategory where it’s expected to get an array containing male and jeans. 1   Get  Ready First of all, we need to enable pretty URLs.  In the application … Read more

How to install Yii2 framework on Xampp and SEO friendly URL

Step by step guide to Install Yii2 framework by composer or from Archive file on Xampp. Then  instruction to how to make easy to understand and internet searcher agreeable URLs for your web application. There are two Yii2 framework templates available: Basic Template – A basic frontend application template. Advanced Template – Consisting of a … Read more