30
Frameworks SACHEEN DHANJIE

Dev traning 2016 symfony

Embed Size (px)

Citation preview

Page 1: Dev traning 2016   symfony

FrameworksSACHEEN DHANJIE

Page 2: Dev traning 2016   symfony

Sacheen DhanjieSenior Developer @ Afrihost.com

Page 3: Dev traning 2016   symfony

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

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

PHP Frameworks

Page 6: Dev traning 2016   symfony

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

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

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

Setting up Symfony

Page 10: Dev traning 2016   symfony

Setting up Symfony

Page 11: Dev traning 2016   symfony

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

Home

Page 13: Dev traning 2016   symfony

The Page – IT WORKS!

Page 14: Dev traning 2016   symfony

The Console• ./bin/console

Page 15: Dev traning 2016   symfony

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

Bundles• Creating a bundle• ./bin/console generate:bundle

Page 17: Dev traning 2016   symfony

Bundles

Page 18: Dev traning 2016   symfony

MVC• Model• View • Controller

Page 19: Dev traning 2016   symfony

On To The Code!

Page 20: Dev traning 2016   symfony

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

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

Displaying the page

Page 23: Dev traning 2016   symfony

ModelThis is the data source./bin/console doctrine:generate:entity

Page 24: Dev traning 2016   symfony

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

Creating the table• ./bin/console doctrine:schema:create

Page 26: Dev traning 2016   symfony

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

Create a new Controller\ExampleBundle\Controller\DefaultController::userAction

Page 28: Dev traning 2016   symfony

Create a new Viewsrc/ExampleBundle/Resources/views/Default/user.html.twig

Page 29: Dev traning 2016   symfony

Check out the result!

Page 30: Dev traning 2016   symfony

Questions?