Yii PHP App

Yii

by uab

PHP Framework
Helps with: PHP
Similar to: ThinkPHP App Cloudways PHP SDK App Laravel App Drupal App More...
Source Type: Open
License Types:
BSD
Supported OS:
Languages: C

What is it all about?

Yii is a high-performance PHP framework best for developing Web 2.0 applications.

Key Features

* Fast: Yii only loads the features that you need. It has powerful caching support. It is explicitly designed to work efficiently with AJAX. * Secure: Security comes as standard with Yii. It includes input validation, output filtering, SQL injection and Cross-site scripting prevention. * Professional: Yii helps you develop clean and reusable code. It follows the MVC pattern, ensuring a clear separation of logic and presentation.


Pricing

Yearly
Monthly
Lifetime
Free
Freemium
Trial With Card
Trial No Card
By Quote

Description

free - see site

Product Analysis

PHP

PHP frameworks and libraries

Yii Framework Review

Yii Framework Review

By Alvie Amar | 6/13/2016 | Product Analysis |Beginners

Yii is an open source, object-oriented PHP framework. Yii is a component-based framework with high performance that is good for rapidly developing large-scale web applications. Yii is pronounced as “Yee” or as “ji”, an acronym for "Yes It Is!" which in Chinese means “evolutionary and simple”. Yii empowers usability and promotes clean and dry design which can accelerate the web application development process.

 

In October 2006, after ten months of private development, the first alpha version of Yii was released. Yii began as an endeavor to resolve some of the down sides of the PRADO framework: slow handling of complex pages, steep expectation to absorb information and difficulty to tweak numerous controls.   

 

These are some of the features that make Yii, the best PHP framework:

  • Fast
  • Create Retrieve Update Delete
  • Easy to configure:
  • Highly Secured
  • AJAX enabled widgets
  • Database Access Objects
  • Ready Made Code
  • Authorization & Authentication
  • Model View Controller (MVC) design pattern
  • Library Rich with Extensions

 

The Yii framework likewise offers a wide range of capacities that permit rapidly and effortless development of upgraded web applications. Furthermore, Yii additionally offers astounding documentation and a supportive community.

 

What is Yii good for?

 

Yii is used for developing any type of web application but most importantly Yii helps build complex application rapidly. What makes Yii attractive and popular in development world is that it is known for being malleable, extensible, productively dynamic and measured. The Yii framework reduces overall development time and subsequently will help the client with a more cost efficient base expense.

 

Here are some advantages of using Yii:

  • Yii framework makes the web development a more methodical movement, with the assistance of MVC or model view controller.
  • lightweight and the code is particularly enhanced
  • CRUD Feature - literally saves heaps of time and makes the procedure much less demanding
  • Database tables as objects which helps you steer clear of complex queries and make your tasks simple.
  • Security measure safety incorporate prevention of cross-site scripting (XSS), cross-site demand forgery (CSRF) and cookie tampering.
  • It has a great documentation

 

Examples and code snippets

 

I expect you already have Apache, PHP (5.1 or greater), and MySQL installed on your system. And after that, download the latest and stable version that Yii has.

 

Moving on, each web application has a directory structure, and Yii applications likewise needs to keep up a various hierarchical structure inside the web root. To make a skeleton application with a reasonable registry structure we can use Yii's command line tool "yii"c. Explore to the web root and type the following:

<YiiRoot>frameworkyiic webapp yiitest

 

This will make the skeleton application called yiitest with the minimum required files. Inside you will discover index.php which serves as an entry script; it acknowledges user requests and chooses which controller ought to handle the request.

As a beginner once you setup default yii venture, next step will be the way to change this static login form to dynamic, i.e. username and password originates from database.

 

Here we will add new variable to the class. i.e. userType

 

Path: models/LoginForm.php

class LoginForm extends CFormModel
{
   public $username;
   public $password;
   public $rememberMe;
   public $userType; // added new member
   private $_identity;
   public function __construct($arg='Front') { // default it is set to Front     
       $this->userType = $arg;
   }
   //==== rest code will be as it is ====
   public function authenticate($attribute,$params)
   {
       if(!$this->hasErrors())
       {
           $this->_identity=new UserIdentity($this->username,$this->password);
           $this->_identity->userType = $this->userType; // this will pass flag to the UserIdentity class
           if(!$this->_identity->authenticate())
               $this->addError('password','Incorrect username or password.');
       }
   }

Same like LoginForm, adding new member to the class.

 

Path: components/UserIdentity.php

<?php
class UserIdentity extends CUserIdentity
{   
   public $userType = 'Front';
   public function authenticate()
   {
       if($this->userType=='Front') // This is front login
       {
           // check if login details exists in database
                       $record=User::model()->findByAttributes(array('username'=>$this->username));
           if($record===null)
           {
               $this->errorCode=self::ERROR_USERNAME_INVALID;
           }
           else if($record->password!==$this->password)            // here I compare db password with password field
           {
               $this->errorCode=self::ERROR_PASSWORD_INVALID;
           }
           else
           {  
               $this->setState('userId',$record->userId);
               $this->setState('name', $record->firstName.' '.$record->lastName);
               $this->errorCode=self::ERROR_NONE;
           }
           return !$this->errorCode;
       }
       if($this->userType=='Back')// This is admin login
       {
           // check if login details exists in database
                       $record=AdminUser::model()->findByAttributes(array('email'=>$this->username));  // here I use Email as user name which comes from database
           if($record===null)
           {
               $this->errorCode=self::ERROR_USERNAME_INVALID;
           }
           else if($record->password!==base64_encode($this->password)) // let we have base64_encode password in database
           {
               $this->errorCode=self::ERROR_PASSWORD_INVALID;
           }
           else
           {  
               $this->setState('isAdmin',1);
               $this->setState('userId',$record->userId);
               $this->setState('name', $record->name);
               $this->errorCode=self::ERROR_NONE;
           }
           return !$this->errorCode;
       }
   }
}

Presently all is set, we simply need to use LoginForm object in controller files.

 

Path: Controllers/Front/SiteController.php

$model=new LoginForm('Front'); // Front side login form which will use 'User' module

Path: Controllers/Back/SiteController.php 

$model=new LoginForm('Back'); // Admin side login form which will use 'AdminUser' module

This is just a simple example of how to write sample codes under Yii framework.

Conclusion

 

These days, there are numerous different PHP frameworks that are already accessible in the market and every developer must decide for himself which framework to use or not to use. Some software engineers these days have utilized the Yii framework. For them, it's convenient and simple to use, nonetheless, that doesn't mean that other frameworks are not helpful or not useful at all.  It's no one but you who can recognize what framework you should use. In the event that you are not yet familiar with this framework, this would be a great time for you to learn new and awesome things.

By Alvie Amar | 6/13/2016 | Product Analysis

{{CommentsModel.TotalCount}} Comments

Your Comment

{{CommentsModel.Message}}

Top DiscoverSDK Experts

User photo
3355
Ashton Torrence
Web and Windows developer
GUI | Web and 11 more
View Profile
User photo
1490
Ronan McCarthy
Cross-Platform & Web developer.
Web | Mobile and 6 more
View Profile
User photo
1230
Gary Green
Expert programmer, Ask what you want
Web | JavaScript and 3 more
View Profile
User photo
1130
Harry Gold
Experienced Web developer.
Web | JavaScript and 3 more
View Profile
Show All

Interested in becoming a DiscoverSDK Expert? Learn more

X

Compare Products

Select up to three two products to compare by clicking on the compare icon () of each product.

{{compareToolModel.Error}}

Now comparing:

{{product.ProductName | createSubstring:25}} X
Compare Now