Click here for EduSec Demo EduSec Screenshots

An Introduction to Yii Framework

On 2014-12-26 - By Janvi Kapopara

 

What is FRAMEWORK?

Framework is a unified computing architecture encompassing an operating system, API, GUI, applications.

Framework's design aim is to provide full hardware based computing functionality with no additional software but it does support running x86 programs on an x86 simulator.

What is Yii ?

Yii is a high performance, component-based PHP framework for rapidly developing modern Web applications.

Yii is a generic Web programming framework, meaning that it can be used for developing all kinds of Web applications using PHP.

Because of its component-based architecture and sophisticated caching support, it is especially suitable for developing large-scale applications such as portals, forums, content management systems (CMS), e-commerce projects, Restful Web services, and so on.

Features :

Yii implements the MVC (Model-View-Controller) design pattern and promotes code organization based on that pattern.

Models represent data,business logic and rules.

Views are output representation front end.

Controllers take input data and convert it into commands for models and views.

  • Yii takes the philosophy that code should be written in a simple yet elegant way.

  • Yii will never try to over-design things mainly for the purpose of strictly following some design pattern.

  • Yii provide ready-to-use features: query builders and ActiveRecord for both relational and NoSQL databases.

  • Yii provide Form input and validation ,AJAX-enabled widgets,Skinning and theming,Web services.

  • Yii also provide Error handling and logging and Security,Extension library etc...

  • You can customize source code.

Yii Versions :

  • Currently Yii has two major versions available: 1.1 and 2.0.

  • Version 1.1 is the old generation.

  • Version 2.0 is a complete rewrite of Yii,

  • Yii 2.0 requires PHP 5.4.0 or above.

Yii is a pure OOP-based framework. Yii 2.0 also makes use of the latest features of PHP, such as namespaces and traits.

--------------------------------------------

Installing Yii :

--------------------------------------------

Install Yii with two different ways, using Composer or by downloading an archive file.

(*) Installing from an Archive File:

1) Download the archive file from www.yiiframework.com.

Download one of the following archive files, and then extract it to a Web-accessible folder:

  • Yii 2 with basic application template

  • Yii 2 with advanced application template

2) Unpack/Extract the downloaded file to your www folder. and then rename it with your application name for example: MyFirstApp

3) Change the config/web.php file by entering a secret key for the cookie Validation Key configuration item.

Give proper key in : 'cookieValidationKey' => 'enter your secret key here',

like : 'cookieValidationKey' => 'testingapp',

4) open browser and type localhost/MyFirstApp/

your application is successfully created.

Upto this you just create simple application.

----------------------------------------------------------------------------------------------------------------

Now try to configure with you database.

first of all create database : and create some tables in that.Now connect with your application:

5) return [

'class' => 'yii\db\Connection',

'dsn' => 'mysql:host=localhost;dbname=test123',

'username' => 'root',

'password' => 'ubuntu',

'charset' => 'utf8',

];

6) You can then access Gii through the following URL:

localhost/MyFirstApp/web/index.php?r=gii

Now you can create Model Generator and CRUD Generator.

 

--------------------------------------------------------------------------------------------------------------------------------

Model Generator - This generator generates an Active Record class for the specified database table.

CRUD Generator - This generator generates a controller and views that implement CRUD (Create, Read, Update, and Delete) operations for the specified data model.

Controller Generator - This generator helps you to quickly generate a new controller class, one or several controller actions and their corresponding views.

Form Generator - This generator generates a view script file that displays a form to collect input for the specified model class.

Module Generator - This generator helps you to generate the skeleton code needed by a Yii module.

Extension Generator - This generator helps you to generate the files needed by a Yii extension.