SlideShare a Scribd company logo
1 of 29
Download to read offline
Introduction to Yii
Framework
Tuan Nguyen
Web Developer at Tuoi Tre Online
nganhtuan63@gmail.com
Content

1.  Why I choose Yii Framework?

2.  Yii rich features. (Stuff I like)

3.  A practical folder structure for Web Application with Yii.

4.  Q&A.
1. Why I choose Yii Framework?
- Demand:

To build a robust and solid CMS. (Easy for both Dev., End-Users)

Previous Frameworks I worked with:

+ Zend Framework.
+ CakePHP.
+ MVC Framework made by myself.

Previous CMS I worked with:

+ Drupal
+ Wordpress
+ Other enterprise CMS.
1. Why I choose Yii Framework?
To get started, follow these links in order:

1. http://www.yiiframework.com/tour/ - Learn basic flow of creating new app.
2. http://www.yiiframework.com/doc/blog/ - Create a simple blog with Yii.
3. http://www.yiiframework.com/doc/guide/ - Learn features & components of
   Yii.

Advantages:
- Yii performance - Optimize with APC cache and Lazy Loading -
    http://www.yiiframework.com/performance/
- Very good and clear documents.
- Rich of modules and extensions.

Disadvantages:
- Forum discussions is not really active.
- Community is not as big as others.
Yii Rich Features
Features I usually work with:
  •  MVC Design Pattern and Request Handle Workflow.
  •  New Application Generator. (demo)
  •  Support multi-database systems (MySQL, SQLlite,...). (demo)
  •  URLManager (demo)
  •  Gii Generator: CRUD, Model, Form, Module,...your own generator. (demo)
  •  Controllers, Filters, AccessControl and Views (demo)
  •  Model - Working with database (CActiveRecord,...) - Rules and Validators. (demo)
  •  Form - Handle user input data - Rules and Validators (demo)
  •  Flexible OOP (Object-Oriented Programming). (demo)
----------------------------------------------------------------------------------------------------------------------
  •  Asset Manager
  •  Error Handler & Log Management
  •  Support multi-caching mechanism. (demo)
  •  Session and Cookie Management. (demo)
  •  Application Security (CSRF, Cookie validation,...). (demo)
  •  User Authentication with RBAC.
  •  Extending Yii - Extensions and Modules
  •  ...check more at: http://www.yiiframework.com/doc/guide/
Yii Rich Features
MVC Design Pattern and Request Handle Workflow

- http://www.yiiframework.com/doc/guide/1.1/en/basics.mvc
Yii Rich Features
MVC Design Pattern and Request Handle Workflow

- http://www.yiiframework.com/doc/guide/1.1/en/basics.mvc
Yii Rich Features
New Application Generator - Demo

- Run php yii/framework/yiic.php webapp /location
- Run and Test new application
Yii Rich Features
New Application Generator - Demo
Yii Rich Features
URLManager configuration

- Do not over-use URLManager due to downgrade of performance.
   (Using .htaccess as much as possible)
Yii Rich Features
Support multi-database systems (MySQL, SQLlite,...)

- Yii database is built on top of PDO. You can switch betweeb DBMS (MySQL,
    SQL,...) without the need to change application code

- Database configuration in protected/config/main.php
Yii Rich Features
Gii Generator: Model, Controller, CRUD,...Your Own generator

Demo:

- Config database connection first.
- Create new User Table in Database.
CREATE TABLE `yiisample`.`user` (
   `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
   `name` VARCHAR( 255 ) NOT NULL ,
   `email` VARCHAR( 255 ) NOT NULL ,
   `status` TINYINT( 2 ) NOT NULL DEFAULT '0'
) ENGINE = INNODB;


- Enable Gii in Applicaion
- Using Gii to generate code.
Yii Rich Features
Controllers, Filters, AccessControl and Views

Demo:

- Learn the basic workflow of controllers and views.
- Learn using filters with AccessControl.
- Learn more about the views:
    www.yiiframework.com/wiki/249/understanding-the-view-rendering-flow/
Yii Rich Features
Models (CActiveRecord, DAO...)

Demo CActiveRecord:

+ http://www.yiiframework.com/doc/guide/1.1/en/database.ar

- Using CActiveRecord to manage Table in Database.
- Features of CActiveRecord:

+ Rules and Validators
+ Behaviors and Events
+ Integreate data to Widgets, CActiveForm,...

Demo DAO:

+ http://www.yiiframework.com/doc/guide/1.1/en/database.dao
Yii Rich Features
Models - CActiveRecord vs DAO

CActiveRecord:
- Good for Inputting (rules, validators,...).
- Quick deploy thanks to Gii Generator.
- Easy to handle.

DAO:
- Less memory.
- Good for retrieving data.

Advice:
Caching and choose DAO to deploy application fast first. Implement by DAO
    later.
http://www.yiiframework.com/forum/index.php/topic/25825-dao-vs-activerecord-
    methods/
http://www.sheldmandu.com/php/php-mvc-frameworks/yii-dao-vs-active-record-
    performance
Yii Rich Features
Forms - CActiveForm

- It is based on Model Concept to collect user data.
- It support rules and validators like Model.
- Demo ContactForm with rules and validators
Yii Rich Features
Flexible Object-Oriented Programming (OOP)

- In Yii, you can extend any core class you want. Keep core code clean and
    logical.

- Demo with User Components.

To manage Users, Yii use 2 components/classes:

+ CWebUser : a component in application variable. It stores basic user
   information of current request (username, email, login by cookie).

+ CUserIdentity : a class to help user "Log in" to system. (Allow users to login
   by using File Data, Pre-Defined data or Database data,...)
Yii Rich Features
Flexible Object-Oriented Programming (OOP)
                                                CWebUser
User Login Workflow
                                                Login by Login Form
                      CUserIdentity will
  Login By            check login information   If identity is ok and no error, the
  Form                from user                 user will be truly logged in to
  User types his                                system by creating session for
  username and        You can implement         that user.
  password            core class here
                                                Login by Cookie

                                                If the cookie user send in request
                                                is ok (with some secure check).
                                                The User will be logged into the
                                                system like above.
  Login By
  Cookie
                                                You can implement core class
  User send its
                                                here
  cookie in the
  request
Yii Rich Features
Session and Cookie Management

- Yii supports Session and Cookie wrapper class.

Session:
- You can use Session Handler by File, Database or Memcache.

'session' => array(
               'class' => 'CDbHttpSession',
               'connectionID' => 'db',
               'autoCreateSessionTable'=>false,
               'sessionTableName'=>'gxc_session',
               'sessionName'=>'gxc_session_id' //Should Change for Different //Apps
 ),

You can implement/extend CDbHttpSession for your own use.
Yii Rich Features
Session and Cookie Management

Cookie:

- Writing to Cookie:
Yii::app()->request->cookies['cookie_name'] = new CHttpCookie('cookie_name', $value);


- Read from Cookie:
$cookie = Yii::app()->request->cookies['cookie_name']->value;


http://www.yiiframework.com/wiki/152/cookie-management-in-yii

Web User Cookie:
           'user'=>array(
                            'class'=>'cms.modules.user.components.GxcUser',

                                          'allowAutoLogin'=>true,
                                         'autoRenewCookie'=>true,
                                         'loginUrl'=>array('site/login'),
                                  'stateKeyPrefix'=>'gxc_u_', //Should Change for Different Apps
                            ),
Yii Rich Features
Application Security (CSRF, Cookie validation,...)

- Yii supports CSRF, Cookie Validation,...
- Learn more at:

http://www.yiiframework.com/doc/guide/1.1/en/topics.security

http://www.yiiframework.com/wiki/275/how-to-write-secure-yii-applications/
Yii Rich Features
Asset Managers

Demo:

- Using Asset Managers in Module to publish Asset Files. (Which we can't
   directly access due to .htaccess restrict)
- Demo with Rights module.
Yii Rich Features
Error Handler and Log Management

- Setup Error handler in config file.
- Log Management:

+ Write Log to File.
+ Display Log on Website.
+ Intergrate with PHP Quick Profiler extension.

http://www.yiiframework.com/extension/phpquickprofiler/
Yii Rich Features
Multi-Caching Mechanism

- Support: File Cache, Database Cache, APC Cache, Memcache,...Switch
   between easily.

http://www.yiiframework.com/doc/guide/1.1/en/caching.data
Yii Rich Features
User Authentication with RBAC.

- Yii supports RBAC for access control.
- In RBAC, there are 3 levels: Role, Task, Operations
- Popular extension to manage RBAC (Rights extension -
    www.yiiframework.com/extension/rights/ )
Yii Rich Features
Extending Yii - Extensions

Thanks to flexible Yii structure, you can easily extend Yii to:

+ Override core components.
+ Create Behaviors
+ Create Widgets
+ Create Module
+ ...More at

http://www.yiiframework.com/doc/guide/1.1/en/extension.overview
Practical Folder Structure
--apps
-----common
-----backend
-----frontend
-----console
--core
----yii

http://www.yiiframework.com/wiki/374/yiiboilerplate-setup-a-professional-
    project-structure-in-seconds/
Q&A
For more information or discussion:

- Nguyễn Anh Tuấn

- Email: nganhtuan63@gmail.com
- Website: http://nganhtuan.com
- Facebook: https://www.facebook.com/nganhtuan63

- Check my open source Yii CMS: http://www.gxccms.com
Thank you!
For more information or discussion:

- Nguyễn Anh Tuấn

- Email: nganhtuan63@gmail.com
- Website: http://nganhtuan.com
- Facebook: https://www.facebook.com/nganhtuan63

- Check my open source Yii CMS: http://www.gxccms.com

More Related Content

What's hot

PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterPHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterKHALID C
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introductionCommit University
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code IgniterAmzad Hossain
 
Having fun with code igniter
Having fun with code igniterHaving fun with code igniter
Having fun with code igniterAhmad Arif
 
Introduction to CodeIgniter
Introduction to CodeIgniterIntroduction to CodeIgniter
Introduction to CodeIgniterPiti Suwannakom
 
JSF basics
JSF basicsJSF basics
JSF basicsairbo
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriverRajathi-QA
 
Building Web Application Using Spring Framework
Building Web Application Using Spring FrameworkBuilding Web Application Using Spring Framework
Building Web Application Using Spring FrameworkEdureka!
 
Progressive EPiServer Development
Progressive EPiServer DevelopmentProgressive EPiServer Development
Progressive EPiServer Developmentjoelabrahamsson
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Fahad Golra
 
Microsoft identity platform and device authorization flow to use azure servic...
Microsoft identity platform and device authorization flow to use azure servic...Microsoft identity platform and device authorization flow to use azure servic...
Microsoft identity platform and device authorization flow to use azure servic...Sunil kumar Mohanty
 
What You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSFWhat You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSFMax Katz
 

What's hot (20)

PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterPHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniter
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introduction
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
Having fun with code igniter
Having fun with code igniterHaving fun with code igniter
Having fun with code igniter
 
Introduction to CodeIgniter
Introduction to CodeIgniterIntroduction to CodeIgniter
Introduction to CodeIgniter
 
Jsf presentation
Jsf presentationJsf presentation
Jsf presentation
 
JSF basics
JSF basicsJSF basics
JSF basics
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
Building Web Application Using Spring Framework
Building Web Application Using Spring FrameworkBuilding Web Application Using Spring Framework
Building Web Application Using Spring Framework
 
Progressive EPiServer Development
Progressive EPiServer DevelopmentProgressive EPiServer Development
Progressive EPiServer Development
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 
Microsoft identity platform and device authorization flow to use azure servic...
Microsoft identity platform and device authorization flow to use azure servic...Microsoft identity platform and device authorization flow to use azure servic...
Microsoft identity platform and device authorization flow to use azure servic...
 
Mvc4
Mvc4Mvc4
Mvc4
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
What You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSFWhat You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSF
 
Introduction to jsf 2
Introduction to jsf 2Introduction to jsf 2
Introduction to jsf 2
 
Reactjs Basics
Reactjs BasicsReactjs Basics
Reactjs Basics
 

Viewers also liked

A site in 15 minutes with yii
A site in 15 minutes with yiiA site in 15 minutes with yii
A site in 15 minutes with yiiAndy Kelk
 
Introduction to YII framework
Introduction to YII frameworkIntroduction to YII framework
Introduction to YII frameworkNaincy Gupta
 
Why choose Yii framework?
Why choose Yii framework?Why choose Yii framework?
Why choose Yii framework?goodcore
 
Yii Training session-1
Yii Training session-1Yii Training session-1
Yii Training session-1AkkiCredencys
 
YiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newYiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newAlexander Makarov
 
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.Bicol IT.org
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in YiiIlPeach
 
Cake Php 1.2 (Ocphp)
Cake Php 1.2 (Ocphp)Cake Php 1.2 (Ocphp)
Cake Php 1.2 (Ocphp)guest193fe1
 
Yii PHP MVC Framework presentation silicongulf.com
Yii PHP MVC Framework presentation silicongulf.comYii PHP MVC Framework presentation silicongulf.com
Yii PHP MVC Framework presentation silicongulf.comChristopher Cubos
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedAlexander Makarov
 

Viewers also liked (19)

Yii framework
Yii frameworkYii framework
Yii framework
 
Yii Framework
Yii FrameworkYii Framework
Yii Framework
 
yii framework
yii frameworkyii framework
yii framework
 
Yii framework
Yii frameworkYii framework
Yii framework
 
A site in 15 minutes with yii
A site in 15 minutes with yiiA site in 15 minutes with yii
A site in 15 minutes with yii
 
Introduction to YII framework
Introduction to YII frameworkIntroduction to YII framework
Introduction to YII framework
 
Yii framework
Yii frameworkYii framework
Yii framework
 
Why choose Yii framework?
Why choose Yii framework?Why choose Yii framework?
Why choose Yii framework?
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
 
Yii Training session-1
Yii Training session-1Yii Training session-1
Yii Training session-1
 
Introduce Yii
Introduce YiiIntroduce Yii
Introduce Yii
 
FUTEX 2015 Programme gb
FUTEX 2015 Programme gbFUTEX 2015 Programme gb
FUTEX 2015 Programme gb
 
YiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newYiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's new
 
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in Yii
 
Cake Php 1.2 (Ocphp)
Cake Php 1.2 (Ocphp)Cake Php 1.2 (Ocphp)
Cake Php 1.2 (Ocphp)
 
Yii PHP MVC Framework presentation silicongulf.com
Yii PHP MVC Framework presentation silicongulf.comYii PHP MVC Framework presentation silicongulf.com
Yii PHP MVC Framework presentation silicongulf.com
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developed
 
Yii workshop
Yii workshopYii workshop
Yii workshop
 

Similar to Introduction Yii Framework

Yii Framework Security
Yii Framework SecurityYii Framework Security
Yii Framework SecurityIlko Kacharov
 
Introduction to Yii & performance comparison with Drupal
Introduction to Yii & performance comparison with DrupalIntroduction to Yii & performance comparison with Drupal
Introduction to Yii & performance comparison with Drupalcadet018
 
Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in YiiIlPeach
 
Authentication
AuthenticationAuthentication
Authenticationsoon
 
Sea surfing in asp.net mvc
Sea surfing in asp.net mvcSea surfing in asp.net mvc
Sea surfing in asp.net mvcmagda3695
 
yii_Presentation_new
yii_Presentation_newyii_Presentation_new
yii_Presentation_newujash joshi
 
Java - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionJava - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionMazenetsolution
 
session and cookies.ppt
session and cookies.pptsession and cookies.ppt
session and cookies.pptJayaprasanna4
 
Microsoft Teams community call - February 2020
Microsoft Teams community call - February 2020Microsoft Teams community call - February 2020
Microsoft Teams community call - February 2020Microsoft 365 Developer
 
World 2013 - Pushing MicroStrategy to the Limit, The Hacker Way
World 2013 - Pushing MicroStrategy to the Limit, The Hacker WayWorld 2013 - Pushing MicroStrategy to the Limit, The Hacker Way
World 2013 - Pushing MicroStrategy to the Limit, The Hacker WayBryan Brandow
 
Testing mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkTesting mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkSusannSgorzaly
 
Security asp.net application
Security asp.net applicationSecurity asp.net application
Security asp.net applicationZAIYAUL HAQUE
 
Java EE Application Security With PicketLink
Java EE Application Security With PicketLinkJava EE Application Security With PicketLink
Java EE Application Security With PicketLinkpigorcraveiro
 
Configuring kerberos based sso in weblogic
Configuring kerberos based sso in weblogicConfiguring kerberos based sso in weblogic
Configuring kerberos based sso in weblogicHarihara sarma
 

Similar to Introduction Yii Framework (20)

Yii Framework Security
Yii Framework SecurityYii Framework Security
Yii Framework Security
 
Introduction to Yii & performance comparison with Drupal
Introduction to Yii & performance comparison with DrupalIntroduction to Yii & performance comparison with Drupal
Introduction to Yii & performance comparison with Drupal
 
Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in Yii
 
Authentication
AuthenticationAuthentication
Authentication
 
Sea surfing in asp.net mvc
Sea surfing in asp.net mvcSea surfing in asp.net mvc
Sea surfing in asp.net mvc
 
ASP.NET Lecture 5
ASP.NET Lecture 5ASP.NET Lecture 5
ASP.NET Lecture 5
 
Cache Security- The Basics
Cache Security- The BasicsCache Security- The Basics
Cache Security- The Basics
 
Java EE Services
Java EE ServicesJava EE Services
Java EE Services
 
Chapter 19
Chapter 19Chapter 19
Chapter 19
 
yii_Presentation_new
yii_Presentation_newyii_Presentation_new
yii_Presentation_new
 
Java - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionJava - Servlet - Mazenet Solution
Java - Servlet - Mazenet Solution
 
session and cookies.ppt
session and cookies.pptsession and cookies.ppt
session and cookies.ppt
 
Microsoft Teams community call - February 2020
Microsoft Teams community call - February 2020Microsoft Teams community call - February 2020
Microsoft Teams community call - February 2020
 
World 2013 - Pushing MicroStrategy to the Limit, The Hacker Way
World 2013 - Pushing MicroStrategy to the Limit, The Hacker WayWorld 2013 - Pushing MicroStrategy to the Limit, The Hacker Way
World 2013 - Pushing MicroStrategy to the Limit, The Hacker Way
 
Testing mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkTesting mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP framework
 
Web works hol
Web works holWeb works hol
Web works hol
 
Security asp.net application
Security asp.net applicationSecurity asp.net application
Security asp.net application
 
Java EE Application Security With PicketLink
Java EE Application Security With PicketLinkJava EE Application Security With PicketLink
Java EE Application Security With PicketLink
 
Configuring kerberos based sso in weblogic
Configuring kerberos based sso in weblogicConfiguring kerberos based sso in weblogic
Configuring kerberos based sso in weblogic
 
Ecom2
Ecom2Ecom2
Ecom2
 

Introduction Yii Framework

  • 1. Introduction to Yii Framework Tuan Nguyen Web Developer at Tuoi Tre Online nganhtuan63@gmail.com
  • 2. Content 1.  Why I choose Yii Framework? 2.  Yii rich features. (Stuff I like) 3.  A practical folder structure for Web Application with Yii. 4.  Q&A.
  • 3. 1. Why I choose Yii Framework? - Demand: To build a robust and solid CMS. (Easy for both Dev., End-Users) Previous Frameworks I worked with: + Zend Framework. + CakePHP. + MVC Framework made by myself. Previous CMS I worked with: + Drupal + Wordpress + Other enterprise CMS.
  • 4. 1. Why I choose Yii Framework? To get started, follow these links in order: 1. http://www.yiiframework.com/tour/ - Learn basic flow of creating new app. 2. http://www.yiiframework.com/doc/blog/ - Create a simple blog with Yii. 3. http://www.yiiframework.com/doc/guide/ - Learn features & components of Yii. Advantages: - Yii performance - Optimize with APC cache and Lazy Loading - http://www.yiiframework.com/performance/ - Very good and clear documents. - Rich of modules and extensions. Disadvantages: - Forum discussions is not really active. - Community is not as big as others.
  • 5. Yii Rich Features Features I usually work with: •  MVC Design Pattern and Request Handle Workflow. •  New Application Generator. (demo) •  Support multi-database systems (MySQL, SQLlite,...). (demo) •  URLManager (demo) •  Gii Generator: CRUD, Model, Form, Module,...your own generator. (demo) •  Controllers, Filters, AccessControl and Views (demo) •  Model - Working with database (CActiveRecord,...) - Rules and Validators. (demo) •  Form - Handle user input data - Rules and Validators (demo) •  Flexible OOP (Object-Oriented Programming). (demo) ---------------------------------------------------------------------------------------------------------------------- •  Asset Manager •  Error Handler & Log Management •  Support multi-caching mechanism. (demo) •  Session and Cookie Management. (demo) •  Application Security (CSRF, Cookie validation,...). (demo) •  User Authentication with RBAC. •  Extending Yii - Extensions and Modules •  ...check more at: http://www.yiiframework.com/doc/guide/
  • 6. Yii Rich Features MVC Design Pattern and Request Handle Workflow - http://www.yiiframework.com/doc/guide/1.1/en/basics.mvc
  • 7. Yii Rich Features MVC Design Pattern and Request Handle Workflow - http://www.yiiframework.com/doc/guide/1.1/en/basics.mvc
  • 8. Yii Rich Features New Application Generator - Demo - Run php yii/framework/yiic.php webapp /location - Run and Test new application
  • 9. Yii Rich Features New Application Generator - Demo
  • 10. Yii Rich Features URLManager configuration - Do not over-use URLManager due to downgrade of performance. (Using .htaccess as much as possible)
  • 11. Yii Rich Features Support multi-database systems (MySQL, SQLlite,...) - Yii database is built on top of PDO. You can switch betweeb DBMS (MySQL, SQL,...) without the need to change application code - Database configuration in protected/config/main.php
  • 12. Yii Rich Features Gii Generator: Model, Controller, CRUD,...Your Own generator Demo: - Config database connection first. - Create new User Table in Database. CREATE TABLE `yiisample`.`user` ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` VARCHAR( 255 ) NOT NULL , `email` VARCHAR( 255 ) NOT NULL , `status` TINYINT( 2 ) NOT NULL DEFAULT '0' ) ENGINE = INNODB; - Enable Gii in Applicaion - Using Gii to generate code.
  • 13. Yii Rich Features Controllers, Filters, AccessControl and Views Demo: - Learn the basic workflow of controllers and views. - Learn using filters with AccessControl. - Learn more about the views: www.yiiframework.com/wiki/249/understanding-the-view-rendering-flow/
  • 14. Yii Rich Features Models (CActiveRecord, DAO...) Demo CActiveRecord: + http://www.yiiframework.com/doc/guide/1.1/en/database.ar - Using CActiveRecord to manage Table in Database. - Features of CActiveRecord: + Rules and Validators + Behaviors and Events + Integreate data to Widgets, CActiveForm,... Demo DAO: + http://www.yiiframework.com/doc/guide/1.1/en/database.dao
  • 15. Yii Rich Features Models - CActiveRecord vs DAO CActiveRecord: - Good for Inputting (rules, validators,...). - Quick deploy thanks to Gii Generator. - Easy to handle. DAO: - Less memory. - Good for retrieving data. Advice: Caching and choose DAO to deploy application fast first. Implement by DAO later. http://www.yiiframework.com/forum/index.php/topic/25825-dao-vs-activerecord- methods/ http://www.sheldmandu.com/php/php-mvc-frameworks/yii-dao-vs-active-record- performance
  • 16. Yii Rich Features Forms - CActiveForm - It is based on Model Concept to collect user data. - It support rules and validators like Model. - Demo ContactForm with rules and validators
  • 17. Yii Rich Features Flexible Object-Oriented Programming (OOP) - In Yii, you can extend any core class you want. Keep core code clean and logical. - Demo with User Components. To manage Users, Yii use 2 components/classes: + CWebUser : a component in application variable. It stores basic user information of current request (username, email, login by cookie). + CUserIdentity : a class to help user "Log in" to system. (Allow users to login by using File Data, Pre-Defined data or Database data,...)
  • 18. Yii Rich Features Flexible Object-Oriented Programming (OOP) CWebUser User Login Workflow Login by Login Form CUserIdentity will Login By check login information If identity is ok and no error, the Form from user user will be truly logged in to User types his system by creating session for username and You can implement that user. password core class here Login by Cookie If the cookie user send in request is ok (with some secure check). The User will be logged into the system like above. Login By Cookie You can implement core class User send its here cookie in the request
  • 19. Yii Rich Features Session and Cookie Management - Yii supports Session and Cookie wrapper class. Session: - You can use Session Handler by File, Database or Memcache. 'session' => array( 'class' => 'CDbHttpSession', 'connectionID' => 'db', 'autoCreateSessionTable'=>false, 'sessionTableName'=>'gxc_session', 'sessionName'=>'gxc_session_id' //Should Change for Different //Apps ), You can implement/extend CDbHttpSession for your own use.
  • 20. Yii Rich Features Session and Cookie Management Cookie: - Writing to Cookie: Yii::app()->request->cookies['cookie_name'] = new CHttpCookie('cookie_name', $value); - Read from Cookie: $cookie = Yii::app()->request->cookies['cookie_name']->value; http://www.yiiframework.com/wiki/152/cookie-management-in-yii Web User Cookie: 'user'=>array( 'class'=>'cms.modules.user.components.GxcUser', 'allowAutoLogin'=>true, 'autoRenewCookie'=>true, 'loginUrl'=>array('site/login'), 'stateKeyPrefix'=>'gxc_u_', //Should Change for Different Apps ),
  • 21. Yii Rich Features Application Security (CSRF, Cookie validation,...) - Yii supports CSRF, Cookie Validation,... - Learn more at: http://www.yiiframework.com/doc/guide/1.1/en/topics.security http://www.yiiframework.com/wiki/275/how-to-write-secure-yii-applications/
  • 22. Yii Rich Features Asset Managers Demo: - Using Asset Managers in Module to publish Asset Files. (Which we can't directly access due to .htaccess restrict) - Demo with Rights module.
  • 23. Yii Rich Features Error Handler and Log Management - Setup Error handler in config file. - Log Management: + Write Log to File. + Display Log on Website. + Intergrate with PHP Quick Profiler extension. http://www.yiiframework.com/extension/phpquickprofiler/
  • 24. Yii Rich Features Multi-Caching Mechanism - Support: File Cache, Database Cache, APC Cache, Memcache,...Switch between easily. http://www.yiiframework.com/doc/guide/1.1/en/caching.data
  • 25. Yii Rich Features User Authentication with RBAC. - Yii supports RBAC for access control. - In RBAC, there are 3 levels: Role, Task, Operations - Popular extension to manage RBAC (Rights extension - www.yiiframework.com/extension/rights/ )
  • 26. Yii Rich Features Extending Yii - Extensions Thanks to flexible Yii structure, you can easily extend Yii to: + Override core components. + Create Behaviors + Create Widgets + Create Module + ...More at http://www.yiiframework.com/doc/guide/1.1/en/extension.overview
  • 28. Q&A For more information or discussion: - Nguyễn Anh Tuấn - Email: nganhtuan63@gmail.com - Website: http://nganhtuan.com - Facebook: https://www.facebook.com/nganhtuan63 - Check my open source Yii CMS: http://www.gxccms.com
  • 29. Thank you! For more information or discussion: - Nguyễn Anh Tuấn - Email: nganhtuan63@gmail.com - Website: http://nganhtuan.com - Facebook: https://www.facebook.com/nganhtuan63 - Check my open source Yii CMS: http://www.gxccms.com