Folio3 - An Introduction to PHP Yii

44
www.folio3.com @folio_3

description

An Introduction to PHP Yii. What it is, its key features, how to install, code samples and performance vs other frameworks.

Transcript of Folio3 - An Introduction to PHP Yii

Page 1: Folio3 - An Introduction to PHP Yii

www.folio3.com @folio_3

Page 2: Folio3 - An Introduction to PHP Yii

Agenda Folio3 – Company Overview

Introduction to Yii

Workflow (MVC)

Installation Steps

Features

Some Code Samples

Model

Using Model from Controller

Controller

View

Performance

Page 3: Folio3 - An Introduction to PHP Yii

Folio3 – An Overview

www.folio3.com @folio_3

Page 4: Folio3 - An Introduction to PHP Yii

Folio3 At a Glance

Founded in 2005

Over 200 full time employees

Offices in the US, Canada, Bulgaria & Pakistan

Palo Alto, CA. Sofia, Bulgaria

Karachi, Pakistan

Toronto, Canada

Page 5: Folio3 - An Introduction to PHP Yii

What We Do

We are a Development Partner for our customers

Design software solutions, not just implement them

Focus on the solution – Platform and technology agnostic

Expertise in building applications that are:

Mobile Social Cloud-based Gamified

Page 6: Folio3 - An Introduction to PHP Yii

What We Do

Areas of Focus Enterprise

Custom enterprise applications

Product development targeting the enterprise

Mobile Custom mobile apps for iOS, Android, Windows Phone, BB OS

Mobile platform (server-to-server) development

Social Media CMS based websites for consumers and enterprise (corporate, consumer,

community & social networking)

Social media platform development (enterprise & consumer)

Gaming Social & casual cross platform games (mobile, web, console)

Virtual Worlds

Page 7: Folio3 - An Introduction to PHP Yii

Areas of Focus: Enterprise

Automating workflows

Cloud based solutions

Application integration

Platform development

Healthcare

Mobile Enterprise

Digital Media

Supply Chain

Page 8: Folio3 - An Introduction to PHP Yii

Areas of Focus: Mobile

Serious enterprise applications

for Banks, Businesses

Fun consumer apps for app

discovery, interaction, exercise

gamification and play

Educational apps

Augmented Reality apps

Mobile Platforms

Page 9: Folio3 - An Introduction to PHP Yii

Areas of Focus: Web & Social Media

Community Sites based on

Content Management

Systems

Enterprise Social

Networking

Social Games for Facebook

& Mobile

Companion Apps for games

Page 10: Folio3 - An Introduction to PHP Yii

Why Yii?

IS it fast? ...

IS it secure? ...

IS it professional? ...

IS it right for my next project?

Page 11: Folio3 - An Introduction to PHP Yii

Folio3

Yes It Is!

Page 12: Folio3 - An Introduction to PHP Yii

Yii – An Introduction

www.folio3.com @folio_3

Page 13: Folio3 - An Introduction to PHP Yii

Introduction

Yii is a free, open-source Web application

development framework written in PHP5 that

promotes clean, DRY design and encourages rapid

development. It works to streamline your

application development and helps to ensure an

extremely efficient, extensible, and maintainable

end product.

Source: http://www.yiiframework.com/about/

Page 14: Folio3 - An Introduction to PHP Yii

Introduction – Workflow (MVC)

Source: http://www.yiiframework.com/doc/guide/1.1/en/basics.mvc#a-typical-workflow

Page 15: Folio3 - An Introduction to PHP Yii

Introduction - Installation

Page 16: Folio3 - An Introduction to PHP Yii

Introduction - Installation

Page 17: Folio3 - An Introduction to PHP Yii

Introduction - Installation

Extract the framework folder to any directory with access rights

Page 18: Folio3 - An Introduction to PHP Yii

Introduction - Installation

Extract the requirements folder to a web-

accessible directory

http://www.example.com/requirements

Page 19: Folio3 - An Introduction to PHP Yii

Requirements

Page 20: Folio3 - An Introduction to PHP Yii

Introduction - Installation

Open console (Command Prompt) and run the following

command from a web-accessible directory

/path/to/php.exe /path/to/framework/yiic.php webapp

myfirstyiiapp

Page 21: Folio3 - An Introduction to PHP Yii

Introduction - Installation

That’s it!

Page 22: Folio3 - An Introduction to PHP Yii

Introduction – Installation - Summary

Download

Extract framework folder

Check requirements

Run install command from console

Page 23: Folio3 - An Introduction to PHP Yii

Introduction – Installation - Preview

Page 24: Folio3 - An Introduction to PHP Yii

Features

www.folio3.com @folio_3

Page 25: Folio3 - An Introduction to PHP Yii

Features

Page 26: Folio3 - An Introduction to PHP Yii

Features

Skinning and theming

You can select theme at project level, controller level, action

level Or based on some condition in action.

Error handling and logging

Errors are handled and presented more nicely, and log

messages can be categorized, filtered and routed to different

destinations.

Page 27: Folio3 - An Introduction to PHP Yii

Features

Automatic code generation

Yii provides a set of spontaneous and highly extensible code

generation tools that can help you quickly generate the code

you need for features such as form input, CRUD.

Unit and functionality testing

Test-Driven Development - using PHPUnit and Selenium

Remote Control

Page 28: Folio3 - An Introduction to PHP Yii

Features

Authentication and authorization

Yii has built-in authentication support. It also supports

authorization via hierarchical role-based access control.

Layered caching scheme

Yii supports data caching, page caching, fragment caching

and dynamic content. The storage medium of caching can

be changed easily without touching the application code.

Page 29: Folio3 - An Introduction to PHP Yii

Features – Extensions

Auth (59)

Caching (25)

Console (25)

Database (133)

Date and Time (31)

Error Handling (6)

File System (39)

Logging (37)

Mail (29)

Networking (25)

Security (20)

User Interface (606)

Validation (82)

Web Service (104)

Others (385)

Page 30: Folio3 - An Introduction to PHP Yii

Code Samples

www.folio3.com @folio_3

Page 31: Folio3 - An Introduction to PHP Yii

Model Class class Post extends CActiveRecord

{

/**

* Retrieves a list of models based on the current search/filter conditions.

* @return CActiveDataProvider the data provider that can return the models based

on the search/filter conditions.

*/

public function search()

{

$criteria=new CDbCriteria;

$criteria->compare('content ',$this->content );

$criteria->compare('title ',$this->title ,true);

return new CActiveDataProvider($this, array(

'criteria'=>$criteria,

));

}

}

Page 32: Folio3 - An Introduction to PHP Yii

Controller class PostController extends Controller {

/**

* Displays a particular model.

* @param integer $id the ID of the model to be displayed

*/

public function actionView($id)

{

$post = Post::model()->findByPk($id);

if(!$post)

throw new CHttpException(404);

$this->render('view', array(

'post' => $post,

));

}

}

Page 33: Folio3 - An Introduction to PHP Yii

Using Model From Controller

Create $post = new Post;

$post->title = 'sample post';

$post->content = 'post body

content';

$post->save(); <- This is validated

Select $post=Post::model()->find(array(

'select'=>'title',

'condition'=>'postID=:postID',

'params'=>array(':postID'=>2),

));

Update $post = Post::model()->findByPk(2);

$post->title = ‘New title’;

$post->save(); <- This is validated

Page 34: Folio3 - An Introduction to PHP Yii

View $this->breadcrumbs=array(

'Posts'=>array('index'),

$post>title,

);

?>

<h1>View Post #<?php echo $post>id; ?></h1>

<?php $this->widget('zii.widgets.CDetailView', array(

'data'=>$post,

'attributes'=>array(

'title', 'content',

),

)); ?>

Page 35: Folio3 - An Introduction to PHP Yii

Performance

www.folio3.com @folio_3

Page 36: Folio3 - An Introduction to PHP Yii

Performance – Comparison with other frameworks

Source: http://www.yiiframework.com/performance

Page 37: Folio3 - An Introduction to PHP Yii

Performance – Lazy loading example

Sch

em

a

/** * Create a relation in TblUser Model Class with User Role (tbl_role) table */ public function relations() { return array( 'userRole' => array(self::BELONGS_TO, 'TblRole', 'user_role_id'), ); } Tb

lUse

r M

od

el

Page 38: Folio3 - An Introduction to PHP Yii

Performance – Lazy loading example

<table> <tr><th>User id</th><td><?php echo $user->id; ?></td></tr> <tr><th>User name</th><td><?php echo $user->username; ?></td></tr> <tr><th>Role</th><td><?php echo $user->user_role_id; ?></td></tr> </table>

If a property of only user model is accessed, only that table will be queried

Page 39: Folio3 - An Introduction to PHP Yii

Performance – Lazy loading example

<table> <tr><th>User id</th><td><?php echo $user->id; ?></td></tr> <tr><th>User name</th><td><?php echo $user->username; ?></td></tr> <tr><th>Role</th><td><?php echo $user->userRole->role_name; ?></td></tr> </table>

If a property of related mode is accessed, only then it will query related model

Page 40: Folio3 - An Introduction to PHP Yii

Performance – Drupal & Yii

Source: http://erickennedy.org/Drupal-7-Reasons-to-Switch

Page 41: Folio3 - An Introduction to PHP Yii

Performance – Drupal & Yii

Source: http://erickennedy.org/Drupal-7-Reasons-to-Switch

Page 42: Folio3 - An Introduction to PHP Yii

Performance – Drupal & Yii

Source: http://erickennedy.org/Drupal-7-Reasons-to-Switch

Page 43: Folio3 - An Introduction to PHP Yii

References

http://www.yiiframework.com

http://www.yiiframework.com/extensions/

http://www.yiiframework.com

http://erickennedy.org/Drupal-7-Reasons-to-

Switch

Page 44: Folio3 - An Introduction to PHP Yii

Contact

For more details about our Yii development services or

our web development expertise, please get in touch

with us.

[email protected]

US Office: (408) 365-4638

www.folio3.com