PHP Professional এবং Zend Certified PHP Engineer (ZCPE ) Course এ সীমিত সংখ্যক আসন বাকি আছে। আগ্রহীদেরকে অতিসত্বর মাসুদ আলম স্যার এর সাথে যোগাযোগ করার জন্য অনুরোধ করা যাচ্ছে। স্যার এর মোবাইল নম্বর : ০১৭২২ ৮১ ৭৫ ৯১

Introducing Yii PHP Framework Extensions

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.

Yii-logo

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-

  1. Download the extension from Yii’s extension repository.
  2. Unpack the extension under the extensions/xyz subdirectory of application base directory, where xyz is the name of the extension.
  3. 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.

  1. bootstrap: This extension brings together Yii and Bootstrap, Twitter’s HTML, CSS and JavaScript toolkit. It provides a wide range of widgets that allow you to easily use Bootstrap with Yii.
  2. uploadmultifiles: Using this extension you can upload multiple files at a single time which can also contain multiple extensions.
  3. 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.
  4. 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.
  5. yiimailer: Yii extension for sending HTML emails with layouts using PHPMailer
  6. 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.
  7. 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.
  8. cfile: This extension offers commonly used functions for filesystem objects (files and directories) manipulation like Create, Purge, Copy, Rename, Move etc.
  9. nestedsetbehavior: This extension allows managing trees stored in database as nested sets. It’s implemented as Active Record behavior.
  10. 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 –

http://localhost:8080/demoyiiext/

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.

yii welcome screen

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.

http://www.yiiframework.com/extension/bootstrap/

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.

yii project structures

Copy and paste your bootstrap folder inside this extensions folder.

Step 3: Configure
We already downloaded and placed bootstrap inside our project to use. Now we need to do a little configuration to let Yii know, bootstrap is in the room. One important information need to mansion. You may already know bootstrap is a CSS framework. We can download it from its home page and we may need jQuery as well, which is another JavaScript library. In our case of Yii bootstrap extension, we have everything inside our downloaded bootstrap folder. So everything is ready to use.

Write the following line of code in demoyiiext/protected/config/main.php at the beginning of the file.

Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');

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 –

config bootstrap components

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 –

configuring layout

As simple, as it is. We are all done. Now open your browser and try to resize your window. See what happened. Cool Right???

bootstrap responsive layout

Conclusion
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

Hej, I’m from Bangladesh. Learning programming is one of the freaking decisions I have taken in my life. Because, it makes me and my life crazy. I have great weakness on open source technologies. Perhaps, that’s why I do not know any closed source language. I fall in love with programming, when I started my undergraduate in East West University. Till now, I can not live without it.

2 comments on “Introducing Yii PHP Framework Extensions

Leave a Reply

Your email address will not be published. Required fields are marked *