Author: Awais Farooq

  • Rules of URL

    A URL rule is an instance if yii\web\UrlRule. The urlManager components uses the URL rules declared in its rules property when the pretty URL format is enabled. To parse a request, the URL manager obtains the rules in the order they are declared and looks for the first rule. Step 1 − Modify the urlManager component in the config/web.php file. Step 2 − Go to your…

  • URL Routing

    To change the default route of the application, you should configure the defaultRoute property. Step 1 − Modify the config/web.php file in the following way. Step 2 − Got to http://localhost:8080/index.php. You will see the default contact page. To put your application in maintenance mode temporarily, you should configure the yii\web\Application::$catchAll property. Step 3 − Add the following function to the SiteController. Step 4 − Then, modify the config/web.php file in…

  • URL Formats

    When a Yii application processes a requested URL, first, it parses the URL into a route. Then, to handle the request, this route is used to instantiate the corresponding controller action. This process is called routing. The reverse process is called URL creation. The urlManager application component is responsible for routing and URL creation. It provides two methods…

  • Responses

    When a web application handles a request, it generates a response object, which contains HTTP headers, body, and HTTP status code. In most cases, you will use the response application component. By default, it is an instance of yii\web\Response. To manage response HTTP status codes, use the yii\web\Response::$statusCode property. The default value of yii\web\Response::$statusCode is 200. Step 1 − Add a…

  • HTTP Requests

    Requests are represented by the yii\web\Request object, which provides information about HTTP headers, request parameters, cookies, and so forth. The methods get() and post() return request parameters of the request component. Example − Step 1 − Add an actionTestGet function to the SiteController of the basic application template. Step 2 − Now go to http://localhost:8080/index.php?r=site/testget&id=1&name=tutorialspoint&message=welcome, you will see the following. To retrieve parameters of other request methods (PATCH, DELETE,…

  • Creating Extensions

    Let us create a simple extension displaying a standard “Hello world” message. This extension will be distributed via the Packagist repository. Step 1 − Create a folder called hello-world in your hard drive but not inside the Yii basic application template). Inside the hello-world directory, create a file named composer.json with the following code. We have declared that we are using the…

  • Extensions

    Extensions are packages specifically designed to be used in Yii applications. You can share your own code as an extension or use third-party extensions to add features to your application. Using Extensions Most extensions are distributed as Composer packages. Composer installs packages from Packagist – the repository for Composer packages. To install a third-party extension,…

  • Asset Conversion

    Instead of writing CSS or JS code, developers often use extended syntax, like LESS, SCSS, Stylus for CSS and TypeScript, CoffeeScript for JS. Then they use special tools to convert these files into real CSS and JS. The asset manager in Yii converts assets in extended syntax into CSS and JS, automatically. When the view is rendered, it will include the…

  • Assets

    An asset is a file (css, js, video, audio or image, etc.) that may be referenced in a web page. Yii manages assets in asset bundles. The purpose of an asset bundle is to have a group of related JS or CSS files in the code base and to be able to register them within a single PHP call. Asset…

  • Layouts

    Layouts represent the common parts of multiple views i.e. for example, page header and footer. By default, layouts should be stored in the views/layouts folder. Let us have a look at the main layout of the basic application template − This layout generates the HTML page that is common for all pages. The $content variable is the rendering result…