Upload
georg-sorst
View
916
Download
4
Tags:
Embed Size (px)
DESCRIPTION
A short introduction to PHP and Symfony
Citation preview
FINDOLOGIC GMBHGEORG M. [email protected]
There are plenty of other frameworks in the sea -PHP + Symfony
WebDev Meetup 20.11.2013
FINDOLOGIC
◼ Search for online stores◼ >100M queries / month◼ A dozen servers◼ One of Salzburg’s most successful
start-ups
Business
LAN
BBQ
Trachty Friday
We’re hiring
DEVELOPERS DEVELOPERS DEVELOPERS!
History
◼ Born in the web 20 years ago◼ Form interpreter to replace perl◼ Core is backed by a company (Zend)◼ 1M to 100M hostnames in 10 years
Stack Overflow tags
Source: http://hewgill.com/~greg/stackoverflow/stack_overflow/tags/
W3Techs
Source: http://w3techs.com/technologies/overview/programming_language/all
Usage
◼ eCommerce: osCommerce, Zen Cart, Magento, PrestaShop, OpenCart, Oxid, xtCommerce, Shopware
◼ CMS: Wordpress, Joomla, Drupal◼ Other: Wikipedia, Digg, Facebook
The good
◼ Dead simple: <?php echo “Hello world”;
◼ Runs everywhere◼ Documentation, Community,
Extensions
The good
◼ Image processing, databases, mails, character encoding, XML built-in
◼ Few keywords and operators, high readability
The bad
◼ Spaghetti code◼ Very loose typing: null == false == "" == 0 == "0" == array()
◼ Inconsistent code base: strpos(), str_rot13(), library not OO
◼ Arbitrary filesystem structure
The getting better
◼ OO; Closures, Iterators, Generators◼ Standard PHP Library (SPL): queues,
stacks, lists, iterators◼ Tools: PHPUnit, PHPDocumentor,
Mess Detector, Checkstyle
Old school
$numbers = array(1, 2, 3, 4, 5);$divisor = 3; $filtered = array();foreach ($numbers as $number) { if ($number % $divisor == 0) { $filtered[] = $number; }}
Middle school
$numbers = array(1, 2, 3, 4, 5);$divisor = 3;
$filter = create_function('$number', “return (\$number % $divisor == 0);”);$filtered = array_filter($numbers, $filter);
New school
$numbers = array(1, 2, 3, 4, 5);$divisor = 3; $filter = function($number) use ($divisor) { return ($number % $divisor == 0);};$filtered = array_filter($numbers, $filter);
Questions?
PHP Frameworks
◼ MVC◼ OO◼ ORM◼ Templates◼ ...
Symfony
◼ MVC, OO◼ Created by Sensio labs◼ Documentation, Community, Events
Symfony
◼ URL Conventions◼ CRUD generators◼ Doctrine ORM, Twig templates◼ Loosely coupled components◼ Dependency injection
Demo Time
Summary
“PHP is the Nickelback of programming languages”
- Jeff Atwood, Stack Exchange
Summary
“The only conclusion I can draw is that building a compelling application is far more important than choice of language”
- Jeff Atwood, Stack Exchange
Thanks!
Backup: Install instructions
1. Change user: sudo su - www-data -s /bin/bash2. Download Symfony 2.3 Standard Edition (without Vendors): http://symfony.com/download3. Setup git repository: http://symfony.com/doc/current/cookbook/workflow/new_project_git.html4. Install composer: curl -sS https://getcomposer.org/installer | php5. Install libraries: php composer.phar install6. Configure: http://localhost/~georg/webdev/web/config.php
a. pdo_sqlite
b. db path: %kernel.root_dir%/data/example.db
c. no password7. Generate bundle: php app/console generate:bundle8. Generate entity: php app/console generate:doctrine:entity9. Drop the old DB schema: php app/console doctrine:schema:drop --force10. Generate DB schema: php app/console doctrine:schema:create11. Generate CRUD: php app/console generate:doctrine:crud12. http://localhost/~georg/webdev/web/app_dev.php/post/13. Add pretty CRUD bundle: https://github.com/jordillonch/CrudGeneratorBundle14. Install new bundle: php composer.phar update15. Delete the old CRUD: rm -fr src/FINDOLOGIC/ExampleBundle/Resources/views/Post/
src/FINDOLOGIC/ExampleBundle/Controller/PostController.php src/FINDOLOGIC/ExampleBundle/Form/PostType.php src/FINDOLOGIC/ExampleBundle/Tests/Controller/PostControllerTest.php
16. Generate new CRUD: php app/console jordillonch:generate:crud17. Fill created_at automatically:
http://stackoverflow.com/questions/17321893/automatic-values-for-updated-at-created-at-in-doctrine
a. Remove created_at from src/FINDOLOGIC/ExampleBundle/Form/PostType.php18. http://localhost/~georg/webdev/web/app_dev.php/post/