Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Symfony2 for Frontend Specialists

Symfony2 for Frontend Specialists

Covers most of what a frontend designer needs to be able to be great at working with Symfony2.

Joshua Estes

July 18, 2012
Tweet

More Decks by Joshua Estes

Other Decks in Education

Transcript

  1. Install the io-symfony-standard git clone [email protected]:io-symfony-standard.git project-name cd project-name rm

    -rf .git/ cp app/config/parameters.yml.dist app/config/parameters.yml curl -s http://getcomposer.org/installer | php php composer.phar install git init git remote add origin [email protected]:project-name.git git add . git commit -m “initial commit” git push origin master
  2. Application Structure project/ app/ ← config stuff (some templates) build/

    ← jenkins build src/ ← code & templates vendor/ ← contains code web/ ← web root http://symfony.com/doc/current/book/page_creation.html#the-directory-structure
  3. Open thy browser • http://localhost/app_dev.php – development mode – edit

    your css without having to rebuild • http://localhost/app.php – Production – For this to look right, you need to install assets and dump assetic – app.php is optional
  4. Where is it? • ::base.html.twig – app/Resources/views/base.html.twig • iostudioDefaultBundle:Default:index.html.twig –

    src/iostudio/DefaultBundle/Resources/views/Default/index.html.twig • iostudioDefaultBundle:Foo:bar.html.twig – src/iostudio/DefaultBundle/Resources/views/Foo/bar.html.twig • iostudioDefaultBundle::layout.html.twig – src/iostudio/DefaultBundle/Resources/views/layout.html.twig
  5. Assetic • Manage your assets • Place them in src/*/*/Resources/public

    – src/iostudio/DefaultBundle/Resources/public/{js,css,images} • minify your javascript/stylesheets
  6. Assetic Example {% stylesheets “bundles/iostudiodefault/css/main.css” “bundles/iostudiodefault/css/other.css” filter=”?yui_css,cssrewrite” %} <link rel=”stylesheet”

    href=”{{ asset_url }}” /> {% endstylesheets %} • Pulls files from web/bundles/iostudiodefault/css/ • php app/console assets:install web --symlink • filters • yui_css • uses yui compressor to minify stylesheets • the ? will only compress the assets if it's in production environment • cssrewrite • assetic will put the stylesheets in a different location • this filter helps make sure all the url() stuff work correctly
  7. Links • php app/console router:debug – See what there is

    to work with • <a href=”{{ path('homepage') }}”>Home</a> – <a href=”/”>Home</a> • <a href=”{{ path('articles') }}”>Articles</a> – <a href=”/articles”>Articles</a>
  8. Links (continued) • Need an absolute path? – <a href=”{{

    url('home') }}”>Home</a> – <a href=”http://example.com”>Home</a> • <a href="{{ path('article_show', { 'slug': article.slug }) }}">{{ article.title }}</a> – <a href="/article/show/this-is-the-slug">Article</a>
  9. Images/Assets • <img src=”{{ asset('images/logo.png') }}” /> • <script src=”{{

    asset('js/app.js') }}”></script> • <img src=”{{ asset('bundles/iostudiodefault/images/logo.png') }}”/> • Benefits? – No need to worry if deployment puts app in subfolder (ie /app vs /) or not.
  10. CLI, Love it/Hate it • php app/console cache:clear • php

    app/console assetic:dump • php app/console assets:install web • php app/console router:debug • php app/console doctrine:database:create • php app/console doctrine:database:drop • php app/console doctrine:schema:update
  11. Deployment • Merge your working branch into the develop branch

    • Push develop branch • Jenkins takes care of rest – syntax checking