Il layout contiene gli elementi HTML comuni a tutte le pagine del sito.
La struttura finale del sito sarà composta dalla combinazione layout + template.
Il layout in Symfony 1.4.22 è il file in:
jobeet/apps/frontend/templates/layout.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <?php include_http_metas() ?> <?php include_metas() ?> <?php include_title() ?> <link rel="shortcut icon" href="/favicon.ico" /> <?php include_stylesheets() ?> <?php include_javascripts() ?> </head> <body> <?php echo $sf_content ?> </body> </html>
La parte più interessante è:
<?php echo $sf_content ?>
La variabile $sf_content contiene HTML generato dall’azione di Symfony.
Di default, il task generate:project ha creato tre cartelle per i file degli elementi grafici:
– web/images/
– web/css/
– web/js/
In Symfony è possibile definire diversi layout, vediamo un esempio pratico.
actions.class.php
<?php class contenutoActions extends sfActions // estende la classe Symfony { public function executePageone() // http://localhost/jobeet/web/frontend_dev.php/contenuto/pageone { } public function executePagetwo() // http://localhost/jobeet/web/frontend_dev.php/contenuto/pagetwo { $this->setLayout('mio_layout'); } }// END class
pageoneSuccess.php
Page One Success
pagetwoSuccess.php
Page Two Success
layout.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <?php include_http_metas() ?> <?php include_metas() ?> <?php include_title() ?> <link rel="shortcut icon" href="/favicon.ico" /> <?php include_stylesheets() ?> <?php include_javascripts() ?> </head> <body> Layout di default <?php echo $sf_content ?> </body> </html>
mio_layout.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <?php include_http_metas() ?> <?php include_metas() ?> <?php include_title() ?> <link rel="shortcut icon" href="/favicon.ico" /> <?php include_stylesheets() ?> <?php include_javascripts() ?> </head> <body> Mio Layout <?php echo $sf_content ?> </body> </html>
Puntare il browser a:
– http://localhost/jobeet/web/frontend_dev.php/contenuto/pageone
Renderizza:
Layout di default Page One Success
– http://localhost/jobeet/web/frontend_dev.php/contenuto/pagetwo
Renderizza:
Mio Layout Page Two Success
Reference:
http://symfony.com/legacy/doc/jobeet/1_4/it/04?orm=Doctrine