Download - Dev traning 2016 symfony
![Page 1: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/1.jpg)
FrameworksSACHEEN DHANJIE
![Page 2: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/2.jpg)
Sacheen DhanjieSenior Developer @ Afrihost.com
![Page 3: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/3.jpg)
What is a software framework?• It is software that assists in structuring an application, with the most common bells and whistles to get you on running almost instantly.
![Page 4: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/4.jpg)
Why use a framework?• It assist in not coding yourself in a corner.• It allow you to focus on the software you have write• It has all the basics built in already, no need to re-invent the wheel
• It comes with ready made components like, authentication, routing, configuration etc..
![Page 5: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/5.jpg)
PHP Frameworks
![Page 6: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/6.jpg)
Choosing a framework• Choosing a framework can be difficult• Its personal choice• Its up to you, with what you comfortable with• There is no right and wrong when choosing• Contribution and Support in open source is what makes the software a preferred choice.
![Page 7: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/7.jpg)
Symfony• http://symfony.com/• We use it at Afrihost.com• It is the core of the business• We run Symfony 1 and 2 concurrently
![Page 8: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/8.jpg)
Getting Started• Composer
• https://getcomposer.org/• Composer is used to install different components to your application.
• You decide what component you would like to use and you install it - https://packagist.org/
• composer create-project symfony/framework-standard-edition my_project_name
![Page 9: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/9.jpg)
Setting up Symfony
![Page 10: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/10.jpg)
Setting up Symfony
![Page 11: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/11.jpg)
Now what?• We need to view our application in the browser.
• php bin/console server:run• This starts a server on the command line• You would only do this when developing
![Page 12: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/12.jpg)
Home
![Page 13: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/13.jpg)
The Page – IT WORKS!
![Page 14: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/14.jpg)
The Console• ./bin/console
![Page 15: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/15.jpg)
Bundles• Symfony uses the term Bundle, for each unit of packaged code that serves a particular purpose.
• For example, BlogBundle – it’s a bundle that should contain code related to a Blog
• SecurityBundle – should have things related to security stuff
![Page 16: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/16.jpg)
Bundles• Creating a bundle• ./bin/console generate:bundle
![Page 17: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/17.jpg)
Bundles
![Page 18: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/18.jpg)
MVC• Model• View • Controller
![Page 19: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/19.jpg)
On To The Code!
![Page 20: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/20.jpg)
Routing•Routing can be configured by annotations, yml, xml and PHP
•The most common configuration is using annotation as the route is above the controller you are currently working with.
![Page 21: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/21.jpg)
Controllers•The code in a controller must be lean•All business logic must be separated from the controller
•Create manager functions to consolidate business logic to a particular bundle domain.
![Page 22: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/22.jpg)
Displaying the page
![Page 23: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/23.jpg)
ModelThis is the data source./bin/console doctrine:generate:entity
![Page 24: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/24.jpg)
Model• app/config/parameters.yml• Setup the database information in the parameters file
• This file is used for storing all the information required for configuration
• Mail hosts, database connections. Etc..
![Page 25: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/25.jpg)
Creating the table• ./bin/console doctrine:schema:create
![Page 26: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/26.jpg)
Putting it all together• Now we have a model• We can create a view to read the model and a controller to add data to the model
![Page 27: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/27.jpg)
Create a new Controller\ExampleBundle\Controller\DefaultController::userAction
![Page 28: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/28.jpg)
Create a new Viewsrc/ExampleBundle/Resources/views/Default/user.html.twig
![Page 29: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/29.jpg)
Check out the result!
![Page 30: Dev traning 2016 symfony](https://reader036.vdocuments.site/reader036/viewer/2022062522/58acc7e41a28abd3048b6283/html5/thumbnails/30.jpg)
Questions?