Introduction To Yii Framework: Tuan Nguyen Web Developer at Tuoi Tre Online
Introduction To Yii Framework: Tuan Nguyen Web Developer at Tuoi Tre Online
Framework
Tuan Nguyen
Web Developer at Tuoi Tre Online
[email protected]
Content
4. Q&A.
1. Why I choose Yii Framework?
- Demand:
To build a robust and solid CMS. (Easy for both Dev., End-Users)
+ Zend Framework.
+ CakePHP.
+ MVC Framework made by myself.
+ Drupal
+ Wordpress
+ Other enterprise CMS.
1. Why I choose Yii Framework?
To get started, follow these links in order:
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
- Yii database is built on top of PDO. You can switch betweeb DBMS (MySQL,
SQL,...) without the need to change application code
Demo:
Demo:
Demo CActiveRecord:
+ http://www.yiiframework.com/doc/guide/1.1/en/database.ar
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
- In Yii, you can extend any core class you want. Keep core code clean and
logical.
+ 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
Session:
- You can use Session Handler by File, Database or Memcache.
Cookie:
- Writing to Cookie:
Yii::app()->request->cookies['cookie_name'] = new CHttpCookie('cookie_name', $value);
http://www.yiiframework.com/wiki/152/cookie-management-in-yii
'allowAutoLogin'=>true,
'autoRenewCookie'=>true,
'loginUrl'=>array('site/login'),
'stateKeyPrefix'=>'gxc_u_', //Should Change for Different Apps
),
Yii Rich Features
Application Security (CSRF, Cookie validation,...)
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:
http://www.yiiframework.com/extension/phpquickprofiler/
Yii Rich Features
Multi-Caching Mechanism
http://www.yiiframework.com/doc/guide/1.1/en/caching.data
Yii Rich Features
User Authentication with RBAC.
Thanks to flexible Yii structure, you can easily extend Yii to:
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:
- Email: [email protected]
- Website: http://nganhtuan.com
- Facebook: https://www.facebook.com/nganhtuan63
- Email: [email protected]
- Website: http://nganhtuan.com
- Facebook: https://www.facebook.com/nganhtuan63