Friday 6 January 2017

Frame Work YII Frame Work

YII Tutorial

YII framework tutorial
YII framework tutorial provides basic and advanced concepts of YII. Our YII tutorial is designed for beginners and professionals.
YII is a light-weight and open-source framework to develop PHP application.
Our YII tutorial includes all topics of such as YII Features , Upgradation, Installation, Data Structure, MVC, Sessions, Flash Data, Cookies, File Upload, etc.

Prerequisite

Before learning YII you must have the basic knowledge of PHP.

Audience

Our YII tutorial is designed to help beginners and professionals.

Problem

We assure that you will not find any problem in this YII tutorial. But if there is any mistake, please post the problem in contact form.


What is Yii

The Yii is an open-source, light-weighted PHP based framework used to develop a whole web application much faster. It accelerates a web development application rapidly.
The Yii (pronounced as Yee or Jii) is a Chinese name which is an acronym for Yes It Is and it means simple and evolutionary. It is suitable for every sized project giving highly optimized performance.
It uses model-view-controller approach. It includes a code generator called Gii, which writes the code for you and save your time.

History

Qiang Xue founded Yii project on January 1, 2008. It overcomes the slow handling process of complex pages, difficulty to customize many controls and steep learning curve.
On December 3, 2008, after almost one year's development Yii 1.0 version was released for the public.
On October 2014, Yii 2.0.0 was released which is a complete rewrite of the earlier version by keeping the original simplicity and feasibility while adopting the latest technologies to make it better.
In our tutorial we will study about the latest Yii version that is Yii2.

Yii Licensing

Yii is released under New BSD License under which it can be freely used to develop a web application.
Yii documentation is licensed under GNU Free Documentation License (GFDL) which means it can be copied, redistributed or modified before its next version is released.
Yii logo is licensed under Creative Commons Attribution.

Yii Version

Yii has released Yii 1.0, Yii 1.1 and Yii 2.0 with their extensions.
  • Yii 1.0 was released on December 3, 2008. Many other extended versions of 1.0 came into existence. It supported PHP 5.1.0 or above and it is no longer used. It's maintenance stopped in December 31, 2010.
  • Yii 1.1.0 was released in January 10, 2010. Many other extended versions of 1.1.0 came into existence. It supports PHP 5.1.0 or above and is still used. It's maintenance stopped in December 31, 2016.
  • Yii 2.0.0 was released in October 12, 2014. Some extended versions of this version are also released and it also supports PHP 5.1.0 or above.
  • Yii 2 is the current and updated version of Yii. It's last release was Yii 2.0.10 in October 20, 2016

Prerequisites

Yii is a powerful console tool. Hence it is recommended to have a command line access to develop an application.
Following things are required to use Yii:
  • PHP 5.4+
  • Web server

Yii Features

PHP has a lot of frameworks. Yii is one of them. New version Yii2 has a lot of new features. Some of the features are discussed here.
Easy Installation Yii can be downloaded either using Composer or manually. It is advisable to use it using Composer as it saves a lot of time.
Modern Technologies Use Yii framework is completely based on OOPS concepts and uses some advanced features of PHP. All classes are namespaced in Yii, which means it allows to take advantage of their autoloader.
Highly Extensible Every part of Yii framework is highly extensible. It also allows the use of third-parties libraries by installing them with Composer then configuring and including them in autoloader.
Testing Feature Yii2 is integrated with Codecepetion. Codeception is a PHP testing framework that simplifies the process of creating unit, functional and acceptance tests for your application. Codeception makes the testing configuration of an application simple.
Security Security is an important feature for an application and Yii provides a great feature for security. It has several security components that have several methods which helps to create a more secure application.
Less Time for Development To develop an application a lot of tasks are repeated more than once. Yii provide some tools that helps to reduce your time on these kind of tasks. One of the tool is Gii, which quickly creates a web template for:
  • CRUD
  • Models
  • Controllers
  • Extensions
  • Forms
Performance Yii creators have declared it very clearly that delivering high performance is their goal. It provides several tools to enhance the speed of application. Yii offers a higher rate for receiving request per second. And has a less peak memory usage.
MVC Pattern It supports model-view-controller pattern to separate the codes.
Modelling Database Database data can be modeled in terms of objects instead of long SQL statements.
Error Handling & Logging Logged messages can be categorized and routed to the different destinations.
Form Input and Validation It has a set of validators and numerous helper methods which simplifies the task.
Security It is equipped with many security measures to prevent from external attacks.
Layered Caching System It supports data caching, fragment caching, dynamic content and page caching. You can also change the storage medium of cache without touching the application code.
Automatic Code Generation It provides a highly extensible code generation tools that will generate the code for you very quickly such as CRUD and form.
Detailed Documentation you will get a detailed documentation stating every method or property used in Yii.
Skinning and Themeing It provides skinning and themeing mechanism that allows you to quickly switch outlook of a Yii generated website.

Upgradation of Yii1.1 to Yii2

There are many differences between 1.1 and 2.0 version of Yii. It was completely rewritten for version 2.0. There are some major differences between both the versions. Yii2 has introduced some more new features.

Changes regarding PHP

There are many differences in the PHP language used for Yii1.1 and Yii2. Some major changes are listed below.
  • PHP 5.4+
  • Namespaces
  • Anonymous functions
  • Short array syntax is used instead of full syntax
  • In view files, short echo tags <?= are used.
  • Standard PHP library and interfaces
  • Uses Late Static Binding feature.
  • Uses a method of code reuse called Traits.

Namespace

The most important change in Yii2 is the use of namespace. Every class name is namespaced. This naming scheme follows the directory structure means it indicates the location of the corresponding file.

Events

In Yii1, events were defined by an on- method. In Yii2, you can just call trigger() function to use any event name.

Views

The most important change in views is that $this now no longer refers to current controller. Instead, it refers to a view object. To access a controller in the view part use $this->context.

Assets

Yii2 introduces a new concept called asset bundle. An asset bundle is a collection of asset files within a directory. Assets in the bundle are made accessible via Web.

Yii2 Installation

Step 1 Go to Yii official site, http://www.yiiframework.com/
YII Installation 1
Step 2 Click on Download Yii button.
You'll see options like,
  • Install via Composer
  • Install from an archieve file
  • Upgradation from Older Versions
Choose one of them, and go ahead.
Most preferrable way is installing via composer. Hence we'll go with the composer one.
Now, you can either install Yii in Linux or in Windows. Both the Operating Systems have the different procedures to install it.
We'll see installations in both the Operating Systems:
  • Installation in Windows
  • Installation in Linux

Installation in Linux

We are installing our Yii2 framework thorugh Composer. So first we need to install composer on our Linux system.
In order to work composer Yii2 in our systems, some packages need to be installed first to support them.
So let's get started. Open your Terminal and start executing the following code.

Installation of prerequisites for Composer and Yii2 framework

Step 1 The curl installation
YII Installation in linux 1
Step 2 The php5-cli package installation
YII Installation in linux 2
Look at the above snapshot, it is asking for permission, press y and then "enter".
Step 3 The php5-mysql package installation
YII Installation in linux 3
Step 4 The php5-mycrypt package installation
YII Installation in linux 4
To activate it, we need to run the following command.
YII Installation in linux 5
Now these four packages will alwayse remain in your system and you don't need to install them every time while installating Yii framework.

Yii Installation

Let's install the composer globally in our system.
Step 1 The Composer installation
YII Installation in linux 6
Step 2 Installing Composer Globally
YII Installation in linux 7
Step 3 After composer installed, install composer asset plugin.
YII Installation in linux 8
Here, you may be asked for a Token, which indicates GitHub username and password. If you don't have one just create it. It is very easy to create and free to use.
This command allows you to manage asset plugins like css, js, etc which manages npm and bower dependencies.
Now we are ready to install basic and advanced templates.
Step 4 To install Basic template
YII Installation in linux 9
After the download is complete, you can rename it as you want. Our folder is named as basic.
Step 5 To install Advanced template
YII Installation in linux 10
Here we have named it as Advanced.
Step 6 Run it on the browser with the following URL,
http://localhost/Advanced/frontend/web/
YII Installation in linux 11
Look at the above snapshot, you have successfully downloaded your Yii2 framework in your system. Now start your application.

No comments:

Post a Comment