KEMBAR78
Dev traning 2016 symfony | PPTX
Frameworks
SACHEEN DHANJIE
Sacheen Dhanjie
Senior Developer @ Afrihost.com
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.
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..
PHP Frameworks
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.
Symfony
• http://symfony.com/
• We use it at Afrihost.com
• It is the core of the business
• We run Symfony 1 and 2 concurrently
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
Setting up Symfony
Setting up 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
Home
The Page – IT WORKS!
The Console
• ./bin/console
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
Bundles
• Creating a bundle
• ./bin/console generate:bundle
Bundles
MVC
• Model
• View
• Controller
On To The Code!
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.
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.
Displaying the page
Model
This is the data source
./bin/console doctrine:generate:entity
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..
Creating the table
• ./bin/console doctrine:schema:create
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
Create a new Controller
ExampleBundleControllerDefaultController::userAction
Create a new View
src/ExampleBundle/Resources/views/Default/user.html.twig
Check out the result!
Questions?

Dev traning 2016 symfony

  • 1.
  • 2.
  • 3.
    What is asoftware framework? • It is software that assists in structuring an application, with the most common bells and whistles to get you on running almost instantly.
  • 4.
    Why use aframework? • 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..
  • 5.
  • 6.
    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.
  • 7.
    Symfony • http://symfony.com/ • Weuse it at Afrihost.com • It is the core of the business • We run Symfony 1 and 2 concurrently
  • 8.
    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
  • 9.
  • 10.
  • 11.
    Now what? • Weneed 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
  • 12.
  • 13.
    The Page –IT WORKS!
  • 14.
  • 15.
    Bundles • Symfony usesthe 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
  • 16.
    Bundles • Creating abundle • ./bin/console generate:bundle
  • 17.
  • 18.
  • 19.
    On To TheCode!
  • 20.
    Routing • Routing canbe 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.
  • 21.
    Controllers • The codein 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.
  • 22.
  • 23.
    Model This is thedata source ./bin/console doctrine:generate:entity
  • 24.
    Model • app/config/parameters.yml • Setupthe database information in the parameters file • This file is used for storing all the information required for configuration • Mail hosts, database connections. Etc..
  • 25.
    Creating the table •./bin/console doctrine:schema:create
  • 26.
    Putting it alltogether • Now we have a model • We can create a view to read the model and a controller to add data to the model
  • 27.
    Create a newController ExampleBundleControllerDefaultController::userAction
  • 28.
    Create a newView src/ExampleBundle/Resources/views/Default/user.html.twig
  • 29.
  • 30.