Yii workshop

Post on 22-Nov-2014

1.892 views 3 download

Tags:

description

 

Transcript of Yii workshop

IbuildingsEnterprise Web &

Mobile Application Development

2

Agenda

• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.

3

Agenda

• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.

4

About me

• Simone Gentili aka demo or sensorario.

• Php developer since Php3.• Freelance since 2009.• Yii developer since 2010.• Symfony2 developer since 2011.

5

Agenda

• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.

6

Introducing Yii Framework

• Other php framework.• Why Yii?

7

Other PHP Frameworks

• Zend• Symfony• CodeIgniter• Yii• CakePHP• Laravel• Silex• ...

8

Why Yii?

• Yii is rapid!• Secure!• Extensible!• Easy to learn!• Symply works!

9

Agenda

• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.

10

Yii features and components

• MVC.• ActiveRecord and QueryBuilder.• Form.• Ajax-Enabled widgets.• Authentication and authorization.• Skinning and theming.• Web services.• Internationalization and localization.

11

Yii features and components

• Caching data.• Error handling and logging.• Security.• Unit and functional tests.• Code generator.• Friendly with third party code.• Documentation.• Extension library.

12

Agenda

• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.

13

Suggested tools

• Software.• Editors.• Versioning.• Testing.

14

Software

• Webserver.–MAMP.– XAMP.– LAMP.

• PHP.• Editor.• ...

15

Editors

• Netbeans.• Eclipse.• PHPStorm.• CodeLobster.• Vim.

16

Versioning

• github.com• bitbucket.com

17

Testing

• PHPUnit

18

Agenda

• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.

19

Start-up new applications

• Download from yiiframework.com.• Cloning yii from github.com.• Applications with composer.

20

Download yii from yiiframework.com

21

Cloning yii from github.com

22

Create new web application

23

Create new web application

24

My Web Application - Home

25

My Web Application - About

26

My Web Application - Contact

CAPTCHA

27

My Web Application - Contact

28

My Web Application - Login

29

My Web Application - Login

30

MVC in Yii

31

And the other frameworks?

• Really is easy develop with Yii?– Yes it is!

32

MVC Comparison

33

Login

• Model• View• Controller

34

Login

• Model• View• Controller

35

Login - Model

36

Login

• Model• View• Controller

37

Login - View

<?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'login-form', 'enableClientValidation'=>true, 'clientOptions'=>array( 'validateOnSubmit'=>true, ),)); ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <div class="row"> <?php echo $form->labelEx($model,'username'); ?> <?php echo $form->textField($model,'username'); ?> <?php echo $form->error($model,'username'); ?> </div> <div class="row"> <?php echo $form->labelEx($model,'password'); ?> <?php echo $form->passwordField($model,'password'); ?> <?php echo $form->error($model,'password'); ?> </div> <div class="row rememberMe"> <?php echo $form->checkBox($model,'rememberMe'); ?> <?php echo $form->label($model,'rememberMe'); ?> <?php echo $form->error($model,'rememberMe'); ?> </div> <div class="row buttons"> <?php echo CHtml::submitButton('Login'); ?> </div><?php $this->endWidget(); ?>

38

Login - View

39

Login

• Model• View• Controller

40

Login - Controller

41

Agenda

• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.

42

RedRed[one or more [one or more

test fails]test fails]

Refactor code / write new tests

Fix functional code

Refactor code[unbroken tests]

GreenGreen[all test [all test

passes | no passes | no one fails]one fails]

TDD Approach

43

Agenda

• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.

44

A blog example

• Create table.• Enable db component.• Enable Gii.• Change CMenu widget.• Create model with Gii.• Generate CRUD for Post model.• Try generated CRUD.• Some tricks.

45

A blog example

• Create table.• Enable db component.• Enable Gii.• Change CMenu widget.• Create model with Gii.• Generate CRUD for Post model.• Try generated CRUD.• Some tricks.

46

Create table

47

A blog example

• Create table.• Enable db component.• Enable Gii.• Change CMenu widget.• Create model with Gii.• Generate CRUD for Post model.• Try generated CRUD.• Some tricks.

48

Enable db component

49

A blog example

• Create table.• Enable db component.• Enable Gii.• Change CMenu widget.• Create model with Gii.• Generate CRUD for Post model.• Try generated CRUD.• Some tricks.

50

Enable Gii

51

A blog example

• Create table.• Enable db component.• Enable Gii.• Change CMenu widget.• Create model with Gii.• Generate CRUD for Post model.• Try generated CRUD.• Some tricks.

52

Change CMenu Widget

53

A blog example

• Create table.• Enable db component.• Enable Gii.• Change CMenu widget.• Create model with Gii.• Generate CRUD for Post model.• Try generated CRUD.• Some tricks.

54

Create model with Gii

55

Create model with Gii

56

A blog example

• Create table.• Enable db component.• Enable Gii.• Change CMenu widget.• Create model with Gii.• Generate CRUD for Post model.• Try generated CRUD.• Some tricks.

57

Generate CRUD for Post model

58

Generate CRUD for Post model

59

A blog example

• Create table.• Enable db component.• Enable Gii.• Change CMenu widget.• Create model with Gii.• Generate CRUD for Post model.• Try generated CRUD.• Some tricks.

60

Try generated CRUD

61

Create post

62

accessRules

63

A blog example

• Create table.• Enable db component.• Enable Gii.• Change CMenu widget.• Create model with Gii.• Generate CRUD for Post model.• Try generated CRUD.• Some tricks.

64

Create a post

65

Get our username

66

View Post

67

View Post

68

Manage Post

69

Ajax search

70

List Post

71

Page size

72

Pagination

73

Model

• select.• insert.• update.• delete.

74

Model

• select.• insert.• update.• delete.

75

Model - Select

Post::model()->findAll(array( ‘condition’ => ‘id=:id’, ‘params’ => array( ‘:id’ => ‘1’ )));

Post::model()->findByPk(33);

76

Model

• select.• insert.• update.• delete.

77

Model - Insert

78

Model - Insert

$post = new Post();$post->autore = ‘sensorario’;$post->data_post = date(‘Y-m-d’);$post->titolo = ‘Titolo post’;$post->messaggio = ‘Hello world’;$post->save();

79

Model

• select.• insert.• update.• delete.

80

Model - Update

81

Model - Update

$post = Post::model()->findByPk(33);$post->autore = ‘ibuildings’;$post->save();

82

Model

• select.• insert.• update.• delete.

83

Model - Delete

Post::model()->findByPk(33)->delete();

End

Question time

Ibuildings ITALIAFinalmente le tue APP Web & Mobile diventano GRANDI