SlideShare una empresa de Scribd logo
1 de 1
Descargar para leer sin conexión
Open-Source PHP5 MVC Framework
                                                                                                                                            Agile Development



VIEW
PARTIALS, COMPONENTS, SLOTS and COMPONENT SLOTS
                                      PARTIALS                                                                                   SLOTS
  Reusable chunk of template code. A template can include partials whether                  A placeholder that you can put in any of the view elements (in the layout,
  it is in the same module, in another module, or in the global templates/                  a template, or a partial). Filling this placeholder is just like setting a
  directory. Partials have access to the usual symfony helpers and template                 variable. The filling code is stored globally in the response, so you can
  shorcuts, but not to the variables defined in the action calling it, unless               define it anywhere (in the layout, a template, or a partial). Slots are very
  passed explicitly as an argument.                                                         useful to define zones meant to display contextual content.

                   Article Detail     Best Articles     Lastest Articles                         Template                     Layout                        Layout
                                                                                                                      Slot                           Slot
                   Article Partial    Article Partial
                                      Article Partial
                                                        Article Partial
                                                        Article Partial                           Slot 1
                                                                                                               +       1
                                                                                                                                Template
                                                                                                                                              =       1
                                                                                                                                                              Template


                                                                                                                              Slot 2                        Slot 2
                                      Article Partial   Article Partial                           Slot 2


   USING A PARTIAL                                                                          USING A SLOT
  Create a file named _<partial_name>.php, that contains the partial, in:                   To define a slot in a template:
  <myproject>/apps/<myapp>/modules/<mymodule>/templates/                                    Each template has the ability to define the contents of a slot.
  To include a partial:                                                                     As slots are meant to hold HTML code, just write the slot code between
                                                                                            a call to the slot(<slot_name>) and end_slot() helpers.
  <?php include_partial('<module>/<partial_name>’, array('<var>'=>$<var>)) ?>
                                                                                             E.g.: Overriding the 'sidebar' slot content in a template
  Global partials:                                                                                <?php slot('sidebar') ?>
  Should be in: <myproject>/apps/<myapp>/templates/                                                  <!-- custom sidebar code for the current template-->
                                                                                                     <h1>User details</h1>
  To include a global partial:                                                                       <p>name: <?php echo $user->getName() ?></p>
  <?php include_partial('global/<partial_name>’) ?>                                                  <p>email: <?php echo $user->getEmail() ?></p>
                                                                                                  <?php end_slot() ?>

                                                                                            To include a slot:
                                     COMPONENTS
                                                                                             <?php include_slot('<slot_name>’) ?>
  A partial with a logic behind.          Template
  Is like an action, it can pass        Headlines Sidebar
                                                                                            To verify if a slot is defined:
  variables to a template                                                                    <?php has_slot('<slot_name>’) ?>
  partial, except it's much
  faster. The logic is kept in a                                                            The has_slot() helper returns true if the slot has been defined before,
                                                     Headlines Component     Logic          providing a fallback mechanism.
  components.class.php file
  in the actions/ directory,
                                                       Headlines Partial     Presentation    E.g.: Including a 'sidebar' slot in the layout
  and the template is a regular partial.
  You can include components in components,                                                       <div id="sidebar">
  or in the global layout, as in any regular template.                                              <?php if (has_slot('sidebar')): ?>
                                                                                                          <?php include_slot('sidebar') ?>
   USING A COMPONENT                                                                                <?php else: ?>
                                                                                                          <!-- default sidebar code -->
  Presentation:                                                                                           <h1>Contextual zone</h1>
  Create a file named _<component_name>.php, in:                                                          <p>This zone contains links and information relative to the
  <myproject>/apps/<myapp>/modules/<mymodule>/templates/                                                   main content of the page.</p>
   ...                                                                                              <?php endif; ?>
     <?php foreach($news as $headline): ?>                                                        </div>
       <li>
        <?php echo $headline->getPublishedAt() ?>
        <?php echo link_to($headline->getTitle(),'news/show?id='.$headline->getId()) ?>
       </li>
     <?php endforeach ?>
                                                                                                                        COMPONENT SLOTS
   ...                                                                                      A component which varies according to the module calling it. Component
  Logic:                                                                                    slots are named placeholders that you can declare in the view elements.
  Create a file named components.class.php, that is the class inheriting                    For a component slot, the code results from the execution of a component
  from sfComponents, in:                                                                    and the name of this component comes from the view configuration.
  <myproject>/apps/<myapp>/modules/<mymodule>/actions/                                      Useful for breadcrumbs, contextual navigations and dynamic insertions.
  E.g.: <?php                                                                               USING A COMPONENT SLOT
        class newsComponents extends sfComponents{
           public function executeHeadline(){                                               To set a component slot placeholder:
              $c = new Criteria();
              $c->addDescendingOrderByColumn(NewsPeer::PUBLISHED_AT);                        <?php include_component_slot('<component_slot_name>’) ?>
              $c->setLimit(5);
              $this->news = NewsPeer::doSelect($c);                                         To define a default component slot in the view.yml (located in
           }                                                                                <myapp>/config):
        }
                                                                                               default:
                                                                                                components:
  To call a component:
                                                                                                 <component_slot_name>: [<module_name>, <partial_name>]
  include_component('<module>', '<component_name>’, array('<var>'=>$<var>))
   <?php include_component('news', 'headlines') ?>                                          This will call the execute<partial_name> method of the
                                                                                            <module_name>Components class in the components.class.php located
  Components accept additional parameters in the shape of an associative                    in <module_name> module, and will display the _<partial_name>.php
  array. The parameters are available to the partial under their name, and                  located in:
  in the component via the $this object:                                                    <myproject>/apps/<myapp>/modules/<module_name>/templates/
  E.g.: call to the component:
        <?php include_component('news', 'headlines', array('foo' => 'bar')) ?>              To disable a component slot in view.yml (located in <myapp>/config):
        in the component itself:                                                               all:
        <?php echo $this->foo; ?>       // 'bar'                                                components:
        in the _headlines.php partial:                                                            <component_slot_name>: []
        <?php echo $foo; ?>            // 'bar’


http://andreiabohner.wordpress.com                                                                         This cheat-sheet is not an official part of the symfony documentation

Más contenido relacionado

La actualidad más candente

Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
Sowri Rajan
 

La actualidad más candente (6)

Final Defense
Final DefenseFinal Defense
Final Defense
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 
RomaFramework Tutorial Basics
RomaFramework Tutorial BasicsRomaFramework Tutorial Basics
RomaFramework Tutorial Basics
 
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module DevelopmentZen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
 
Graphics programming in Java
Graphics programming in JavaGraphics programming in Java
Graphics programming in Java
 
Deep C
Deep CDeep C
Deep C
 

Destacado

Destacado (7)

Adentrándonos al Framework Symfony
Adentrándonos al  Framework SymfonyAdentrándonos al  Framework Symfony
Adentrándonos al Framework Symfony
 
Desarrollo rápido con PHP y Symfony (I): Introducción a Symfony
Desarrollo rápido con PHP y Symfony (I): Introducción a SymfonyDesarrollo rápido con PHP y Symfony (I): Introducción a Symfony
Desarrollo rápido con PHP y Symfony (I): Introducción a Symfony
 
Symfony. La guia definitiva
Symfony. La guia definitivaSymfony. La guia definitiva
Symfony. La guia definitiva
 
Las buenas prácticas oficiales para aplicaciones Symfony
Las buenas prácticas oficiales para aplicaciones SymfonyLas buenas prácticas oficiales para aplicaciones Symfony
Las buenas prácticas oficiales para aplicaciones Symfony
 
Desarrollo de aplicaciones web con PHP y symfony
Desarrollo de aplicaciones web con PHP y symfonyDesarrollo de aplicaciones web con PHP y symfony
Desarrollo de aplicaciones web con PHP y symfony
 
deSymfony 2013 - Creando aplicaciones web desde otro ángulo con Symfony y A...
deSymfony 2013 -  Creando aplicaciones web desde otro ángulo con Symfony y A...deSymfony 2013 -  Creando aplicaciones web desde otro ángulo con Symfony y A...
deSymfony 2013 - Creando aplicaciones web desde otro ángulo con Symfony y A...
 
Ejercicios de algoritmos
Ejercicios de algoritmosEjercicios de algoritmos
Ejercicios de algoritmos
 

Similar a Symfony Components

Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
Maurizio Pelizzone
 
Process Synchronization Producer-Consumer ProblemThe purpos.docx
Process Synchronization Producer-Consumer ProblemThe purpos.docxProcess Synchronization Producer-Consumer ProblemThe purpos.docx
Process Synchronization Producer-Consumer ProblemThe purpos.docx
stilliegeorgiana
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
Sunil Pandey
 
6 introduction-php-mvc-cakephp-m6-views-slides
6 introduction-php-mvc-cakephp-m6-views-slides6 introduction-php-mvc-cakephp-m6-views-slides
6 introduction-php-mvc-cakephp-m6-views-slides
MasterCode.vn
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 

Similar a Symfony Components (20)

Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012
 
Aspect-oriented programming in Perl
Aspect-oriented programming in PerlAspect-oriented programming in Perl
Aspect-oriented programming in Perl
 
New Stuff In Php 5.3
New Stuff In Php 5.3New Stuff In Php 5.3
New Stuff In Php 5.3
 
Template Toolkit
Template ToolkitTemplate Toolkit
Template Toolkit
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
Templates, partials and layouts
Templates, partials and layoutsTemplates, partials and layouts
Templates, partials and layouts
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
FLossEd-BK Tequila Framework3.2.1
FLossEd-BK Tequila Framework3.2.1FLossEd-BK Tequila Framework3.2.1
FLossEd-BK Tequila Framework3.2.1
 
The Django Book chapter 4 templates (supplement)
The Django Book chapter 4 templates (supplement)The Django Book chapter 4 templates (supplement)
The Django Book chapter 4 templates (supplement)
 
Process Synchronization Producer-Consumer ProblemThe purpos.docx
Process Synchronization Producer-Consumer ProblemThe purpos.docxProcess Synchronization Producer-Consumer ProblemThe purpos.docx
Process Synchronization Producer-Consumer ProblemThe purpos.docx
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
 
6 introduction-php-mvc-cakephp-m6-views-slides
6 introduction-php-mvc-cakephp-m6-views-slides6 introduction-php-mvc-cakephp-m6-views-slides
6 introduction-php-mvc-cakephp-m6-views-slides
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Flyr PHP micro-framework
Flyr PHP micro-frameworkFlyr PHP micro-framework
Flyr PHP micro-framework
 
Bb Tequila Coding Style (Draft)
Bb Tequila Coding Style (Draft)Bb Tequila Coding Style (Draft)
Bb Tequila Coding Style (Draft)
 
Twig for Drupal 8 and PHP | Presented at OC Drupal
Twig for Drupal 8 and PHP | Presented at OC DrupalTwig for Drupal 8 and PHP | Presented at OC Drupal
Twig for Drupal 8 and PHP | Presented at OC Drupal
 

Último

Último (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Symfony Components

  • 1. Open-Source PHP5 MVC Framework Agile Development VIEW PARTIALS, COMPONENTS, SLOTS and COMPONENT SLOTS PARTIALS SLOTS Reusable chunk of template code. A template can include partials whether A placeholder that you can put in any of the view elements (in the layout, it is in the same module, in another module, or in the global templates/ a template, or a partial). Filling this placeholder is just like setting a directory. Partials have access to the usual symfony helpers and template variable. The filling code is stored globally in the response, so you can shorcuts, but not to the variables defined in the action calling it, unless define it anywhere (in the layout, a template, or a partial). Slots are very passed explicitly as an argument. useful to define zones meant to display contextual content. Article Detail Best Articles Lastest Articles Template Layout Layout Slot Slot Article Partial Article Partial Article Partial Article Partial Article Partial Slot 1 + 1 Template = 1 Template Slot 2 Slot 2 Article Partial Article Partial Slot 2 USING A PARTIAL USING A SLOT Create a file named _<partial_name>.php, that contains the partial, in: To define a slot in a template: <myproject>/apps/<myapp>/modules/<mymodule>/templates/ Each template has the ability to define the contents of a slot. To include a partial: As slots are meant to hold HTML code, just write the slot code between a call to the slot(<slot_name>) and end_slot() helpers. <?php include_partial('<module>/<partial_name>’, array('<var>'=>$<var>)) ?> E.g.: Overriding the 'sidebar' slot content in a template Global partials: <?php slot('sidebar') ?> Should be in: <myproject>/apps/<myapp>/templates/ <!-- custom sidebar code for the current template--> <h1>User details</h1> To include a global partial: <p>name: <?php echo $user->getName() ?></p> <?php include_partial('global/<partial_name>’) ?> <p>email: <?php echo $user->getEmail() ?></p> <?php end_slot() ?> To include a slot: COMPONENTS <?php include_slot('<slot_name>’) ?> A partial with a logic behind. Template Is like an action, it can pass Headlines Sidebar To verify if a slot is defined: variables to a template <?php has_slot('<slot_name>’) ?> partial, except it's much faster. The logic is kept in a The has_slot() helper returns true if the slot has been defined before, Headlines Component Logic providing a fallback mechanism. components.class.php file in the actions/ directory, Headlines Partial Presentation E.g.: Including a 'sidebar' slot in the layout and the template is a regular partial. You can include components in components, <div id="sidebar"> or in the global layout, as in any regular template. <?php if (has_slot('sidebar')): ?> <?php include_slot('sidebar') ?> USING A COMPONENT <?php else: ?> <!-- default sidebar code --> Presentation: <h1>Contextual zone</h1> Create a file named _<component_name>.php, in: <p>This zone contains links and information relative to the <myproject>/apps/<myapp>/modules/<mymodule>/templates/ main content of the page.</p> ... <?php endif; ?> <?php foreach($news as $headline): ?> </div> <li> <?php echo $headline->getPublishedAt() ?> <?php echo link_to($headline->getTitle(),'news/show?id='.$headline->getId()) ?> </li> <?php endforeach ?> COMPONENT SLOTS ... A component which varies according to the module calling it. Component Logic: slots are named placeholders that you can declare in the view elements. Create a file named components.class.php, that is the class inheriting For a component slot, the code results from the execution of a component from sfComponents, in: and the name of this component comes from the view configuration. <myproject>/apps/<myapp>/modules/<mymodule>/actions/ Useful for breadcrumbs, contextual navigations and dynamic insertions. E.g.: <?php USING A COMPONENT SLOT class newsComponents extends sfComponents{ public function executeHeadline(){ To set a component slot placeholder: $c = new Criteria(); $c->addDescendingOrderByColumn(NewsPeer::PUBLISHED_AT); <?php include_component_slot('<component_slot_name>’) ?> $c->setLimit(5); $this->news = NewsPeer::doSelect($c); To define a default component slot in the view.yml (located in } <myapp>/config): } default: components: To call a component: <component_slot_name>: [<module_name>, <partial_name>] include_component('<module>', '<component_name>’, array('<var>'=>$<var>)) <?php include_component('news', 'headlines') ?> This will call the execute<partial_name> method of the <module_name>Components class in the components.class.php located Components accept additional parameters in the shape of an associative in <module_name> module, and will display the _<partial_name>.php array. The parameters are available to the partial under their name, and located in: in the component via the $this object: <myproject>/apps/<myapp>/modules/<module_name>/templates/ E.g.: call to the component: <?php include_component('news', 'headlines', array('foo' => 'bar')) ?> To disable a component slot in view.yml (located in <myapp>/config): in the component itself: all: <?php echo $this->foo; ?> // 'bar' components: in the _headlines.php partial: <component_slot_name>: [] <?php echo $foo; ?> // 'bar’ http://andreiabohner.wordpress.com This cheat-sheet is not an official part of the symfony documentation