Sonata Block Bundle - sfPot March 2014
Upcoming SlideShare
Loading in...5
×
 

Sonata Block Bundle - sfPot March 2014

on

  • 2,247 views

 

Statistics

Views

Total Views
2,247
Views on SlideShare
746
Embed Views
1,501

Actions

Likes
7
Downloads
13
Comments
1

13 Embeds 1,501

http://sonata-project.org 1052
http://blog.mmx3.pl 346
http://allframeworks.ru 57
http://www.slideee.com 14
http://www.sonata-project.org 8
http://element.vagrant 8
http://feedly.com 4
https://twitter.com 4
http://www.allframeworks.ru 3
http://www.feedspot.com 2
http://reader.aol.com 1
http://digg.com 1
http://translate.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Sonata Block Bundle - sfPot March 2014 Sonata Block Bundle - sfPot March 2014 Presentation Transcript

  • BlockBundle   Sonata  Project  
  •                SONATA-­‐PROJECT:  BlockBundle   •  Thomas  Rabaix   – Founder  and  Lead  dev  of  Sonata  Project   – Work  @  Ekino   •  Official  sponsor  of  Sonata  Project   •  PHP  Experts   •  Ekino[Drupal|Wordpress]Bundle,  EkinoNewRelicBundle    
  • Web  Developer’s  Job       ~     Let’s  take  a  standard  product  page   hRp://demo.sonata-­‐project.org/shop/product/travel-­‐paris-­‐ tour/1037     ~     The  page  point  to  a  MVC  ac[on:   ProductController::viewProduct   Get  the  product  and  check  validity     ~     How  can  we  reuse  shared  components  ?   Twig’s  extensions:  include,  use,  block     or  Symfony2’s  extension:  render     ...  or  …    
  •                SONATA-­‐PROJECT:  BlockBundle   What  ?   •  BlockBundle   – It  is  used  to  manage  fragments  of  content,  so-­‐ called  blocks,     – and  can  be  incorporated  into  any  page  layout.   – Think  of  “small  MVC  ac[on”  
  •                SONATA-­‐PROJECT:  BlockBundle   Why  ?   •  Rendering  controller  is  not  always  perfect   – Crea[ng  subrequest  can  be  heavy   – Not  everything  fits  into  an  url  =>  controller   – A  controller  cannot  define  or  validate  segngs   – Cannot  handle  cache  backends  (it  is  not  always   about  hRp:  redis,  memcached  or  mongodb)  
  •                SONATA-­‐PROJECT:  BlockBundle   How  ?  
  • THE  RSS  BLOCK  SERVICE   Your  First  Block  Service  
  •                SONATA-­‐PROJECT:  BlockBundle   Let’s  create  your  first  block  service     From   h3p://sonata-­‐project.org/bundles/block/master/ doc/reference/your_first_block.html     ~     A  RSS  Live  Feed  reader  
  • composer require sonata-project/block-bundle:~2.2!
  • A  block  service  is  just  a  service  which  implements  the   BlockServiceInterface  interface.       There  is  only  one  instance  of  a  block  service,  however  there  are  many   block  instances.   1/5  
  • A  block  service  needs  segngs  to  work  properly     and  to  ensure  consistency,       The  service  should  define  a  setDefaultSettings  method  to   configure  the  default  op[ons  (like  a  FormType)   2/5  
  • This  method  must  return  a  Response  object,       this  object  is  used  to  render  the  block.   3/5  
  • A  block  template  is  very  simple.       We  are  looping  on  feeds  or  if  not  defined,  a  error  message  is  displayed.   4/5  
  • We  just  need  to  declare  the  BlockService  as  Service    with  the  tag  sonata.tag!   We  also  need  to  enable  the  block    in  the  sonata_blocks.blocks  sec[on.   5/5  
  • CONCEPT   behind  the  scenes  
  • •  BlockInterface! –  Contains  the  block  informa[on   –  Can  have  children  and  parent   •  BlockContextInterface! –  Contains  data  for  the  current  execu[on   –  Can  be  altered  during  run[me   •  BlockServiceInterface! –  Manipulate  the  BlockInterface! –  Render  a  BlockContextInterface! •  BlockContextManagerInterface! –  Create  a  valid  BlockContext  from  any  provided  data   •  BlockLoaderInterface! –  Call  by  the  BlockContextManager  to  get  a  BlockInterface! •  BlockRendererInterface! –  Render  the  BlockContext! –  Generates  a  valid  Response!
  •                SONATA-­‐PROJECT:  BlockBundle   Rendering  Workflow  
  • CACHE   Speed  up  the  code  
  •                SONATA-­‐PROJECT:  BlockBundle   composer require sonata-project/cache-bundle:~2.1!
  • Cache  Configura[on  
  • Ttl  default  is  84600   extra_cache_keys  can  be  used  to  ovewrite  default   values,  like  ones  aRached  at  run[me  
  • SYMFONY2  INTEGRATION   Small  nice  things  
  • EXTERNAL  INTEGRATIONS   We  are  not  alone  
  • Symfony  CMF  
  • Sylius  
  • Sonata  Page  Bundle  
  • PrestaCMS  
  •                SONATA-­‐PROJECT:  BlockBundle   Other  Features   •  Block  events   •  Javascript  and  Stylesheet  helpers   •  Excep[on  strategy   •  Rapid  Prototyping  
  •                SONATA-­‐PROJECT:  BlockBundle   References   •  hRp://sonata-­‐project.org/bundles/block/ master/doc/index.html   •  hRp://symfony.com/doc/current/cmf/ bundles/block/introduc[on.html  
  • QUESTIONS?   What  the  SonataBlockBundle  does  ?