Yii workshop

2,463 views
2,324 views

Published on

Published in: Technology

Yii workshop

  1. 1. IbuildingsEnterprise Web &Mobile Application Development
  2. 2. 2Agenda• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.
  3. 3. 3Agenda• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.
  4. 4. 4About me• Simone Gentili aka demo orsensorario.• Php developer since Php3.• Freelance since 2009.• Yii developer since 2010.• Symfony2 developer since 2011.
  5. 5. 5Agenda• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.
  6. 6. 6Introducing Yii Framework• Other php framework.• Why Yii?
  7. 7. 7Other PHP Frameworks• Zend• Symfony• CodeIgniter• Yii• CakePHP• Laravel• Silex• ...
  8. 8. 8Why Yii?• Yii is rapid!• Secure!• Extensible!• Easy to learn!• Symply works!
  9. 9. 9Agenda• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.
  10. 10. 10Yii features and components• MVC.• ActiveRecord and QueryBuilder.• Form.• Ajax-Enabled widgets.• Authentication and authorization.• Skinning and theming.• Web services.• Internationalization and localization.
  11. 11. 11Yii 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. 12. 12Agenda• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.
  13. 13. 13Suggested tools• Software.• Editors.• Versioning.• Testing.
  14. 14. 14Software• Webserver.– MAMP.– XAMP.– LAMP.• PHP.• Editor.• ...
  15. 15. 15Editors• Netbeans.• Eclipse.• PHPStorm.• CodeLobster.• Vim.
  16. 16. 16Versioning• github.com• bitbucket.com
  17. 17. 17Testing• PHPUnit
  18. 18. 18Agenda• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.
  19. 19. 19Start-up new applications• Download from yiiframework.com.• Cloning yii from github.com.• Applications with composer.
  20. 20. 20Download yii from yiiframework.com
  21. 21. 21Cloning yii from github.com
  22. 22. 22Create new web application
  23. 23. 23Create new web application
  24. 24. 24My Web Application - Home
  25. 25. 25My Web Application - About
  26. 26. 26My Web Application - ContactCAPTCHA
  27. 27. 27My Web Application - Contact
  28. 28. 28My Web Application - Login
  29. 29. 29My Web Application - Login
  30. 30. 30MVC in Yii
  31. 31. 31And the other frameworks?• Really is easy develop with Yii?– Yes it is!
  32. 32. 32MVC Comparison
  33. 33. 33Login• Model• View• Controller
  34. 34. 34Login• Model• View• Controller
  35. 35. 35Login - Model
  36. 36. 36Login• Model• View• Controller
  37. 37. 37Login - 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); ?> <?phpecho $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. 38. 38Login - View
  39. 39. 39Login• Model• View• Controller
  40. 40. 40Login - Controller
  41. 41. 41Agenda• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.
  42. 42. 42RedRed[one or more[one or moretest fails]test fails]Refactor code / write new testsFix functional codeRefactor code[unbroken tests]GreenGreen[all test passes[all test passes| no one fails]| no one fails]TDD Approach
  43. 43. 43Agenda• About me.• Introducing Yii Framework.• Yii features and components.• Suggested tools.• Start-up new application.• About Test Driven Development.• A blog example.
  44. 44. 44A 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. 45. 45A 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. 46. 46Create table
  47. 47. 47A 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. 48. 48Enable db component
  49. 49. 49A 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. 50. 50Enable Gii
  51. 51. 51A 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. 52. 52Change CMenu Widget
  53. 53. 53A 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. 54. 54Create model with Gii
  55. 55. 55Create model with Gii
  56. 56. 56A 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. 57. 57Generate CRUD for Post model
  58. 58. 58Generate CRUD for Post model
  59. 59. 59A 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. 60. 60Try generated CRUD
  61. 61. 61Create post
  62. 62. 62accessRules
  63. 63. 63A 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. 64. 64Create a post
  65. 65. 65Get our username
  66. 66. 66View Post
  67. 67. 67View Post
  68. 68. 68Manage Post
  69. 69. 69Ajax search
  70. 70. 70List Post
  71. 71. 71Page size
  72. 72. 72Pagination
  73. 73. 73Model• select.• insert.• update.• delete.
  74. 74. 74Model• select.• insert.• update.• delete.
  75. 75. 75Model - SelectPost::model()->findAll(array(‘condition’ => ‘id=:id’,‘params’ => array(‘:id’ => ‘1’)));Post::model()->findByPk(33);
  76. 76. 76Model• select.• insert.• update.• delete.
  77. 77. 77Model - Insert
  78. 78. 78Model - 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. 79. 79Model• select.• insert.• update.• delete.
  80. 80. 80Model - Update
  81. 81. 81Model - Update$post = Post::model()->findByPk(33);$post->autore = ‘ibuildings’;$post->save();
  82. 82. 82Model• select.• insert.• update.• delete.
  83. 83. 83Model - DeletePost::model()->findByPk(33)->delete();
  84. 84. End
  85. 85. Question time
  86. 86. Ibuildings ITALIAFinalmente le tue APP Web & Mobile diventano GRANDI

×