Upload
sacheen-dhanjie
View
151
Download
0
Embed Size (px)
Citation preview
FrameworksSACHEEN DHANJIE
Sacheen DhanjieSenior 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
ModelThis 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\ExampleBundle\Controller\DefaultController::userAction
Create a new Viewsrc/ExampleBundle/Resources/views/Default/user.html.twig
Check out the result!
Questions?