You already heard the roar of Yii framework. Yes, this true. If you don’t know what Yii is, then you need to Google it. If you want to learn about Yii Framework then you need to read previous tutorials of this series, first. Because, in this tutorial, I will discuss about an advance topic. This is called Extensions.
What are Extensions?
Extensions are pieces of software, which help you to accelerate your software building process. In Zend framework it is called Modules. In Drupal it is called Modules and in WordPress it is called plugins. Each extension has a name that uniquely identifies it among all extensions. You can download all of these Yii extensions from Yii’s extension repository
How to Use Yii Extensions?
There are three steps to use these extensions-
- Download the extension from Yii’s extension repository.
- Unpack the extension under the extensions/xyz subdirectory of application base directory, where xyz is the name of the extension.
- 3. Import, configure and use the extension.
10 Most Useful Yii Extensions
This is a rough list of Yii extensions, which are important to almost all projects, these days. So, don’t get crazy about these extensions. Do some research and try to learn about your need.
- uploadmultifiles: Using this extension you can upload multiple files at a single time which can also contain multiple extensions.
- yii-debug-toolbar: The Yii Debug Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel’s content.
- yii-user: Yii PHP Framework extension for registration and management users accounts, like – Login from User Name or Email, Registration, verification email, Recovery password, User profile page etc.
- yiimailer: Yii extension for sending HTML emails with layouts using PHPMailer
- input: This component is everything you need in order to be sure that the input coming from your users is santitized and the data is safe.
- minscript: minScript is a Yii Framework extension which extends clientScript to automatically combine, minify and compress files. The files are served with optimal client cache headers which dramatically improves the web application performance and eases the load on web servers.
- cfile: This extension offers commonly used functions for filesystem objects (files and directories) manipulation like Create, Purge, Copy, Rename, Move etc.
- nestedsetbehavior: This extension allows managing trees stored in database as nested sets. It’s implemented as Active Record behavior.
- egmap: Objet-oriented PHP abstraction to the Google Maps API to ease the process of adding a Google Map on your Yii projects.
Let’s Make Our Hands Dirty
By now we already have enough knowledge about Yii extensions. Let’s use one extension. For this tutorial, I will show you how to use bootstrap extension. Bootstrap is very popular CSS framework, which help us to build a responsive site. Responsive means, different screen size compatibility. To use Yii bootstrap extension, you need to follow the following steps –
Step 1: Create Yii Project
So, download Yii framework and create a project, named demoyiiext from your command line through the following command –
$ yiic webapp demoyiiext
Now open your web browser and go to –
You will see the welcome screen of your project. Try to resize your window. What are you seeing? Part’s of your text disappear and a scroll bar appears at the bottom of your page. If the page is responsive, all the screen contents could adjust with screen size. Right? So, lets make it for kitties.
Step 2: Download Extension
To use any extension, first we need to download it. So, go to Yii bootstrap extension site and download the latest version of it from the following URL.
Now extract and rename the folder to bootstrap. Now the question is, where will we keep it? It’s a good question.
The answer is, if you open your demoyiiext project folder, you will find an extensions folder in htdocs/demoyiiext/protected/ location. This is the home directory of all your extensions. So, be it.
Copy and paste your bootstrap folder inside this extensions folder.
Step 3: Configure
Write the following line of code in demoyiiext/protected/config/main.php at the beginning of the file.
Add the following lines of code inside components array at the same main.php file.
'bootstrap'=>array( 'class'=>'bootstrap.components.Bootstrap', ),
If you find difficulties to get the components array, check the screenshot –
Now we need to let our layout know, we have bootstrap and we are using it. To do this, open demoyiiext/protected/views/layouts/main.php and add the following line of code, just after starting head tag head tag.
<?php Yii::app()->bootstrap->register(); ?>
If you find difficulties to get the head tag, you can check the screenshot –
As simple, as it is. We are all done. Now open your browser and try to resize your window. See what happened. Cool Right???
We have done something very cool today. We have learned the way, how to make a single site for a 19 inch screen as well as a tiny mobile, with minimum amount of code. What will you say this, cool or sexy? Or both?
Happy coding 🙂
Introducing Yii PHP Framework Extensions