14 features that make Yii, the best php framework.

yii

 

Yii, for no doubt is the best php framework currently in the industry. What makes yii special?  Have a look at these 14 exceptional features.

1. Fast

Check out the differences in how many RPS ( Requests per second)  other frameworks can process compared to yii. Check out the drastic difference when we enable the APC extension in php.

framework comparison

Yii is very much known for its speed. Applications developed in yii loads very fast. It is  light weighted  and the code is very much optimized . The lazy loading technique improves the speed of Yii. It neither loads a class until its used   nor creates  an object until its accessed for the first time.

Have  a detailed look at Yii performance .

2. CRUD Feature

Yii got the CRUD  feature. This literally saves heaps of time and makes our process much easier. For instance, If we are building a user creation form, we just need to create the User table and the required fields in the database. And using Gii(link)((a powerful tool of Yii to generate models and controllers) we can easily generate the User model and its CRUD.Thats all and we got the user create,update,delete and manage system all in two or three clicks

 

3. Database tables as objects (so that we don't need to query all time).

We can create model instances. The database modification with these model instances helps you to avoid complex queries and make  your tasks easy. The CDBCriteria  of Yii helps to process very complex database queries easily.

Yii applications can be switched to different databases without any difficulties. Yii got a query builder, and it generates the query. This prevents sql injection and other attacks.
The  ORM approach turns tables into classes and rows into objects.

3.1 Relations

Relations are one of  highlight features of Yii. You can define the relation between multiple tables say One to One, One to Many etc so that we access the related data in a single object avoiding all the comple JOIN (Inner,Outer ) queries of SQL.

Consider two tables User and Profile. User table contains the authentication details and Profile table contains the personal details of the user. We have defined a Has One relation (User have one profile) in the User model .

'userprofile'=>array(self::HAS_ONE, 'Profile', 'userID')

We've set a relation named "userprofile" and we  can access the related profile data through,

$user->userprofile->phonenumber

where phonenumber is the profile user phone number in the profile table.

4. Easy Form Validation.

Working with form and its validation is one of the essential stuff for any website. Using Yii, you can connect your forms with the models (database tables). You can set validation rules for the model. For instance consider a User model (the user database table for user registration ) and there is a field username in it.

array('username','required');

We can set Yii validation rule for the username. And then we create a new object of the User model class and creates a form field for username in the user registration page.

echo $form->textField($user,'username');

where $user is the User model instance and 'username' is the database field for user name. We've created a "required" validation rule for the user name so it gets handled automatically.Once the from is submitted with empty user name field, the error will show up automatically.

5. Great  support for Jquery and ajax.

There are lots of widgets in Yii which have ajax  and jquery support. It do have the jquery dialog, date picker and all so that we just need to call the widgets. We can also send ajax requests easily using the inbuilt ajax buttons in yii.

6. Inbuilt Authentication and Authorization

Authentication

Yii has a default login system, in which we can authorize our user. We just need to connect our User model into it. It got all the essential features required, say session,cookies,error handling etc. We can also manipulate the login system easily

Authorization

Yii got inbuilt role based access controls through which we can create roles to the users. We can limit the access to different sections based on the roles.

if(Yii::app()->user->checkAccess('createUser'))
{
// Create the user
}

Here we've created a task called "createUser" and if the user have permission to the task(creating a user) , he can create a user.

Yii also got accessRules through which we can easily block or allow, logged in,logged out or other users to an action.

7. Theming

Yii applications got theme directory inside so that we can set the theme for the application. Also we can switch easily to different themes inside the config file.This helps the designers to implement designs very easily.

8. Web Services(API Support).

Yii helps easy generation of web services. We can create an action and define a webservice action to it (just 1 line code). And if we try to access the action as a url what we see would be a bulk of xml contents.

9. Caching

Caching helps to improve the performance and speed of your website. Yii helps you to integrate different caching components on different scenarios.This reduces the time required for page load to a great extent.

10. Error Handling

Yii provides great support for error handling. Yii have handleError and handleExcpetion methods which handles all the php warnings and notices.Through Yii, we can raise exceptions (there are lots of built in exceptions) . For example, if a user is requesting an invalid page, we can handle it buy just adding,

throw new CHttpException(404,'The specified page cannot be found.');

And this will raise the 404 error which is what we require in such a scenario.

11. Security

Yii is highly secured. Three major types of attacks to a website are.
1. Cross-site Scripting (XSS)

A typical example is the attack in a poorly made up forum. User can enter malicious javascript code to the forum and it will appear in the forum page. Yii checks for the javascript and malicious codes entered and is capable of blocking those malicious codes form being entered into the website. CHtmlPurifier(inside Yii) does this purpose.

2.Cross-site Request Forgery(CSRF)
These type of attacks are mainly responsible for money loss(mainly from banks) . Yii makes the $_GET requests to retrieve data only, not to change anything in the server.

3.Cookie attacks
Yii got a cookie validation method , which blocks cookies from being modified.

12. Extensions

Yii do have lots of extensions. some what like plugins for wordpress. This makes the complicated development and 3rd party api handling very easy for yii. The twitter bootstrap extension is one of the most rated yii extension. This helps you to integrate twitter bootstrap for your application easily.

Yii Extensions

13. Testing

Yii do have Unit testing and functional testing feature, which helps you in testing and improving your code quality.

14. Great Documentation

Yii do have one of the best documentation system compared to all other frameworks. Each and every single method is documented clearly and thoroughly.

Have a look at the Complete Yii Documentation.

Author: Linjo Joson

Myself Linjo Joson, here in dollarfry , I write articles about creating and optimizing websites as well as making money from your online business. I am PHP/WordPress developer by proffession.I love web analytics and driving traffic to them(doing this for 9 years). You can find me on Google+