Yii workshop

86
Ibuildings Enterprise Web & Mobile Application Development

description

 

Transcript of Yii workshop

Page 1: Yii workshop

IbuildingsEnterprise Web &

Mobile Application Development

Page 2: Yii workshop

2

Agenda

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

Page 3: Yii workshop

3

Agenda

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

Page 4: Yii workshop

4

About me

• Simone Gentili aka demo or sensorario.

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

Page 5: Yii workshop

5

Agenda

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

Page 6: Yii workshop

6

Introducing Yii Framework

• Other php framework.• Why Yii?

Page 7: Yii workshop

7

Other PHP Frameworks

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

Page 8: Yii workshop

8

Why Yii?

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

Page 9: Yii workshop

9

Agenda

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

Page 10: Yii workshop

10

Yii features and components

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

Page 11: Yii workshop

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.

Page 12: Yii workshop

12

Agenda

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

Page 13: Yii workshop

13

Suggested tools

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

Page 14: Yii workshop

14

Software

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

• PHP.• Editor.• ...

Page 15: Yii workshop

15

Editors

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

Page 16: Yii workshop

16

Versioning

• github.com• bitbucket.com

Page 17: Yii workshop

17

Testing

• PHPUnit

Page 18: Yii workshop

18

Agenda

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

Page 19: Yii workshop

19

Start-up new applications

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

Page 20: Yii workshop

20

Download yii from yiiframework.com

Page 21: Yii workshop

21

Cloning yii from github.com

Page 22: Yii workshop

22

Create new web application

Page 23: Yii workshop

23

Create new web application

Page 24: Yii workshop

24

My Web Application - Home

Page 25: Yii workshop

25

My Web Application - About

Page 26: Yii workshop

26

My Web Application - Contact

CAPTCHA

Page 27: Yii workshop

27

My Web Application - Contact

Page 28: Yii workshop

28

My Web Application - Login

Page 29: Yii workshop

29

My Web Application - Login

Page 30: Yii workshop

30

MVC in Yii

Page 31: Yii workshop

31

And the other frameworks?

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

Page 32: Yii workshop

32

MVC Comparison

Page 33: Yii workshop

33

Login

• Model• View• Controller

Page 34: Yii workshop

34

Login

• Model• View• Controller

Page 35: Yii workshop

35

Login - Model

Page 36: Yii workshop

36

Login

• Model• View• Controller

Page 37: Yii workshop

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(); ?>

Page 38: Yii workshop

38

Login - View

Page 39: Yii workshop

39

Login

• Model• View• Controller

Page 40: Yii workshop

40

Login - Controller

Page 41: Yii workshop

41

Agenda

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

Page 42: Yii workshop

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

Page 43: Yii workshop

43

Agenda

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

Page 44: Yii workshop

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.

Page 45: Yii workshop

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.

Page 46: Yii workshop

46

Create table

Page 47: Yii workshop

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.

Page 48: Yii workshop

48

Enable db component

Page 49: Yii workshop

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.

Page 50: Yii workshop

50

Enable Gii

Page 51: Yii workshop

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.

Page 52: Yii workshop

52

Change CMenu Widget

Page 53: Yii workshop

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.

Page 54: Yii workshop

54

Create model with Gii

Page 55: Yii workshop

55

Create model with Gii

Page 56: Yii workshop

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.

Page 57: Yii workshop

57

Generate CRUD for Post model

Page 58: Yii workshop

58

Generate CRUD for Post model

Page 59: Yii workshop

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.

Page 60: Yii workshop

60

Try generated CRUD

Page 61: Yii workshop

61

Create post

Page 62: Yii workshop

62

accessRules

Page 63: Yii workshop

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.

Page 64: Yii workshop

64

Create a post

Page 65: Yii workshop

65

Get our username

Page 66: Yii workshop

66

View Post

Page 67: Yii workshop

67

View Post

Page 68: Yii workshop

68

Manage Post

Page 69: Yii workshop

69

Ajax search

Page 70: Yii workshop

70

List Post

Page 71: Yii workshop

71

Page size

Page 72: Yii workshop

72

Pagination

Page 73: Yii workshop

73

Model

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

Page 74: Yii workshop

74

Model

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

Page 75: Yii workshop

75

Model - Select

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

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

Page 76: Yii workshop

76

Model

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

Page 77: Yii workshop

77

Model - Insert

Page 78: Yii workshop

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();

Page 79: Yii workshop

79

Model

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

Page 80: Yii workshop

80

Model - Update

Page 81: Yii workshop

81

Model - Update

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

Page 82: Yii workshop

82

Model

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

Page 83: Yii workshop

83

Model - Delete

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

Page 84: Yii workshop

End

Page 85: Yii workshop

Question time

Page 86: Yii workshop

Ibuildings ITALIAFinalmente le tue APP Web & Mobile diventano GRANDI