SlideShare a Scribd company logo
Wildan Maulana | wildan [at] tobethink.com #4 The Definitive Guide to symfony  The Basics Of Page Creation Doc. v. 0.1 - 21/04/09
TOC Creating a Module Skeleton Adding a Page Adding an Action
Adding a Template
Passing Information from the Action to the Template Linking to Another Action
Getting Information from the Request Summary
Creating a Module Skeleton > cd ~/myproject > php symfony generate:module frontend content >> dir+  ~/myproject/apps/frontend/modules/content/actions >> file+  ~/myproject/apps/frontend/modules/content/actions/actions.class.php >> dir+  ~/myproject/apps/frontend/modules/content/templates >> file+  ~/myproject/apps/frontend/modules/content/templates/indexSuccess.php >> file+  ~/myproject/test/functional/frontend/contentActionsTest.php >> tokens  ~/myproject/test/functional/frontend/contentActionsTest.php >> tokens  ~/myproject/apps/frontend/modules/content/actions/actions.class.php >> tokens  ~/myproject/apps/frontend/modules/content/templates/indexSuccess.php
The Default Generated Action, in actions/actions.class.php <?php class contentActions extends sfActions { public function executeIndex() { $this->forward('default', 'module'); } }
Adding a Page In symfony, the logic behind pages is stored in the action, and the presentation is in templates.
Adding an Action <?php class contentActions extends sfActions { public function executeShow() { } } Adding an Action Is Like Adding an Execute Method to the Action Class
Adding a Template The content/templates/showSuccess.php Template <p>Hello, world!</p>
Use Alternative PHP Syntax in Template <p>Hello, world!</p> <?php if ($test) { echo &quot;<p>&quot;.time().&quot;</p>&quot;; } ?> The Usual PHP Syntax, Good for Actions, But Bad for Templates <p>Hello, world!</p> <?php if ($test): ?> <p><?php echo time(); ?></p> <?php endif; ?> The Alternative PHP Syntax, Good for Templates
Passing Information from the Action to The Template <?php class contentActions extends sfActions { public function executeShow() { $today = getdate(); $this->hour = $today['hours']; } } Setting an Action Attribute in the Action to Make It Available to the Template <p>Hello, world!</p> <?php if ($hour >= 18): ?> <p>Or should I say good evening? It is already <?php echo $hour ?>.</p> <?php endif; ?> The Template Has Direct Access to the Action Attributes
Note The template already has access to a few pieces of data without the need of any variable setup in the action. Every template can call methods of the  $sf_request ,  $sf_params ,  $sf_response , and  $sf_user  objects. They contain data related to the current request, request parameters, response, and session.
You will soon learn how to use them efficiently.
Linking to Another Action <a href=&quot;/frontend_dev.php/content/update?name=anonymous&quot;> I never say my name </a> Hyperlinks, the Classic Way <p>Hello, world!</p> <?php if ($hour >= 18): ?> <p>Or should I say good evening? It is already <?php echo $hour ?>.</p> <?php endif; ?> <form method=&quot;post&quot; action=&quot;<?php echo url_for('content/update') ?>&quot;> <label for=&quot;name&quot;>What is your name?</label> <input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; value=&quot;&quot; /> <input type=&quot;submit&quot; value=&quot;Ok&quot; /> <?php echo link_to('I never say my name','content/update?name=anonymous') ?> </form> The  link_to() , and  url_for()  Helpers
link_to() helpers // Option argument as an associative array <?php echo link_to('I never say my name', 'content/update?name=anonymous', array( 'class'  => 'special_link', 'confirm'  => 'Are you sure?', 'absolute' => true )) ?> // Option argument as a string <?php echo link_to('I never say my name', 'content/update?name=anonymous', 'class=special_link confirm=Are you sure? absolute=true') ?> // Both calls output the same => <a class=&quot;special_link&quot; onclick=&quot;return confirm('Are you sure?');&quot; href=&quot;http://localhost/frontend_dev.php/content/update/name/anonymous&quot;> I never say my name</a> Most Helpers Accept an Option Argument
Getting Information from the Request <?php class contentActions extends sfActions { // ... public function executeUpdate($request) { $this->name = $request->getParameter('name'); } } Getting Data from the Request Parameter in the Action If there is no data manipulation, use $sf_params  object instead in template : <p>Hello, <?php echo $sf_params->get('name') ?>!</p>
$_POST ,  $_GET , or  $_REQUEST  Usage? Why not use the  $_POST ,  $_GET , or  $_REQUEST  variables instead? Because then your URLs will be formatted differently (as in  http://localhost/articles/europe/france/finance.html,  without ? nor =), the usual PHP variables won't work anymore, and only the routing system will be able to retrieve the request parameters.  And you may want to add input filtering to prevent malicious code injection, which is only possible if you keep all request parameters in one clean parameter holder.

More Related Content

PPT
PPT
PHP Presentation
PPT
PHP Presentation
ODP
Open Power Template 2 presentation
PPT
Joomla security nuggets
PPT
Component and Event-Driven Architectures in PHP
PPT
Web development
PPT
Inroduction to XSLT with PHP4
PHP Presentation
PHP Presentation
Open Power Template 2 presentation
Joomla security nuggets
Component and Event-Driven Architectures in PHP
Web development
Inroduction to XSLT with PHP4

What's hot (20)

PPT
KMUTNB - Internet Programming 3/7
PPT
XML and Web Services with PHP5 and PEAR
PPT
Dealing with Legacy Perl Code - Peter Scott
PPT
Introduction to python scrapping
PPT
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
PPT
LocalizingStyleSheetsForHTMLOutputs
PPT
Web APIs & Google APIs
PDF
The Loop
PPT
ImplementingChangeTrackingAndFlagging
PDF
Various Ways of Using WordPress
PPTX
Meetup django common_problems(1)
PPTX
John Rowley Notes
PPT
AdvancedXPath
PPT
Php Training
PPT
Session Server - Maintaing State between several Servers
PPT
PEAR For The Masses
PPT
Facebook Development with Zend Framework
ODP
Architecting Web Services
PDF
Php tutorial(w3schools)
PPT
Go OO! - Real-life Design Patterns in PHP 5
KMUTNB - Internet Programming 3/7
XML and Web Services with PHP5 and PEAR
Dealing with Legacy Perl Code - Peter Scott
Introduction to python scrapping
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
LocalizingStyleSheetsForHTMLOutputs
Web APIs & Google APIs
The Loop
ImplementingChangeTrackingAndFlagging
Various Ways of Using WordPress
Meetup django common_problems(1)
John Rowley Notes
AdvancedXPath
Php Training
Session Server - Maintaing State between several Servers
PEAR For The Masses
Facebook Development with Zend Framework
Architecting Web Services
Php tutorial(w3schools)
Go OO! - Real-life Design Patterns in PHP 5
Ad

Viewers also liked (20)

PDF
θρησκευτικα B δημ. 1940
PPS
Victor molev metamorphosis
PDF
PDF
PPS
Glyka charaktiras
PDF
PDF
ντροπή για τη δανία ένα φρικτό έγκλημα
PDF
50794192 νάρκες
DOC
οι εξελιξεισ στην εκπαιδευση και οι θεσεισ του συλλογου μασ
PDF
9789601627670
DOC
2010 09-20-116691-theamata
PDF
χαμόγελο
PDF
PDF
PDF
PDF
πρακτικοσ οδηγοσ τησ χειροτεχνιασ του δημοτικου σχολειου η βιβλιοδετικη 1927
PDF
ελλάδα
PDF
πρέσπες
PPTX
Personal Branding
PDF
Perkembangan OpenThink SAS a.k.a SIMMSIT, 2011-2012
θρησκευτικα B δημ. 1940
Victor molev metamorphosis
Glyka charaktiras
ντροπή για τη δανία ένα φρικτό έγκλημα
50794192 νάρκες
οι εξελιξεισ στην εκπαιδευση και οι θεσεισ του συλλογου μασ
9789601627670
2010 09-20-116691-theamata
χαμόγελο
πρακτικοσ οδηγοσ τησ χειροτεχνιασ του δημοτικου σχολειου η βιβλιοδετικη 1927
ελλάδα
πρέσπες
Personal Branding
Perkembangan OpenThink SAS a.k.a SIMMSIT, 2011-2012
Ad

Similar to The Basics Of Page Creation (20)

PPTX
Zend Framework Workshop
PPT
Getting Started with Zend Framework
PDF
Building Web Applications with Zend Framework
PDF
Intro To Mvc Development In Php
PPT
Zend - Installation And Sample Project Creation
KEY
Extending ZF & Extending With ZF
PPTX
They why behind php frameworks
PDF
symfony on action - WebTech 207
PPTX
Lecture 9 - Intruduction to BOOTSTRAP.pptx
PPT
Edp bootstrapping a-software_company
PDF
Working With The Symfony Admin Generator
KEY
Webinar: Zend framework Getting to grips (ZF1)
PDF
web2_lec6.pdf
ODP
CodeIgniter PHP MVC Framework
PPT
Introduction to Zend Framework
KEY
Zend framework: Getting to grips (ZF1)
PDF
Advanced symfony Techniques
PPTX
Day1
PDF
Php Web Development Building Dynamic Websites Web Development Series Edet
Zend Framework Workshop
Getting Started with Zend Framework
Building Web Applications with Zend Framework
Intro To Mvc Development In Php
Zend - Installation And Sample Project Creation
Extending ZF & Extending With ZF
They why behind php frameworks
symfony on action - WebTech 207
Lecture 9 - Intruduction to BOOTSTRAP.pptx
Edp bootstrapping a-software_company
Working With The Symfony Admin Generator
Webinar: Zend framework Getting to grips (ZF1)
web2_lec6.pdf
CodeIgniter PHP MVC Framework
Introduction to Zend Framework
Zend framework: Getting to grips (ZF1)
Advanced symfony Techniques
Day1
Php Web Development Building Dynamic Websites Web Development Series Edet

More from Wildan Maulana (20)

PDF
Hasil Pendataan Potensi Desa 2018
PDF
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
PDF
Ketahanan Pangan #1 : Gerakan Sekolah Menanam Melon
PDF
Pengembangan OpenThink SAS 2013-2014
PDF
ICA – AtoM : Retensi Arsip
PDF
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
PDF
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
PDF
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PDF
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
PDF
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
PDF
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
PDF
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
PDF
Instalasi dan Konfigurasi simpleSAMLphp
PDF
River Restoration in Asia and Connection Between IWRM and River Restoration
PDF
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...
PPT
Penilaian Siswa di Finlandia - Pendidikan Dasar
PDF
Statistik Listrik
PDF
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
PDF
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
PDF
Menggunakan AlisJK : Equating
Hasil Pendataan Potensi Desa 2018
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Ketahanan Pangan #1 : Gerakan Sekolah Menanam Melon
Pengembangan OpenThink SAS 2013-2014
ICA – AtoM : Retensi Arsip
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi dan Konfigurasi simpleSAMLphp
River Restoration in Asia and Connection Between IWRM and River Restoration
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...
Penilaian Siswa di Finlandia - Pendidikan Dasar
Statistik Listrik
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
Menggunakan AlisJK : Equating

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
KodekX | Application Modernization Development
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
KodekX | Application Modernization Development
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
cuic standard and advanced reporting.pdf
Understanding_Digital_Forensics_Presentation.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation_ Review paper, used for researhc scholars
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Diabetes mellitus diagnosis method based random forest with bat algorithm

The Basics Of Page Creation

  • 1. Wildan Maulana | wildan [at] tobethink.com #4 The Definitive Guide to symfony The Basics Of Page Creation Doc. v. 0.1 - 21/04/09
  • 2. TOC Creating a Module Skeleton Adding a Page Adding an Action
  • 4. Passing Information from the Action to the Template Linking to Another Action
  • 5. Getting Information from the Request Summary
  • 6. Creating a Module Skeleton > cd ~/myproject > php symfony generate:module frontend content >> dir+ ~/myproject/apps/frontend/modules/content/actions >> file+ ~/myproject/apps/frontend/modules/content/actions/actions.class.php >> dir+ ~/myproject/apps/frontend/modules/content/templates >> file+ ~/myproject/apps/frontend/modules/content/templates/indexSuccess.php >> file+ ~/myproject/test/functional/frontend/contentActionsTest.php >> tokens ~/myproject/test/functional/frontend/contentActionsTest.php >> tokens ~/myproject/apps/frontend/modules/content/actions/actions.class.php >> tokens ~/myproject/apps/frontend/modules/content/templates/indexSuccess.php
  • 7. The Default Generated Action, in actions/actions.class.php <?php class contentActions extends sfActions { public function executeIndex() { $this->forward('default', 'module'); } }
  • 8. Adding a Page In symfony, the logic behind pages is stored in the action, and the presentation is in templates.
  • 9. Adding an Action <?php class contentActions extends sfActions { public function executeShow() { } } Adding an Action Is Like Adding an Execute Method to the Action Class
  • 10. Adding a Template The content/templates/showSuccess.php Template <p>Hello, world!</p>
  • 11. Use Alternative PHP Syntax in Template <p>Hello, world!</p> <?php if ($test) { echo &quot;<p>&quot;.time().&quot;</p>&quot;; } ?> The Usual PHP Syntax, Good for Actions, But Bad for Templates <p>Hello, world!</p> <?php if ($test): ?> <p><?php echo time(); ?></p> <?php endif; ?> The Alternative PHP Syntax, Good for Templates
  • 12. Passing Information from the Action to The Template <?php class contentActions extends sfActions { public function executeShow() { $today = getdate(); $this->hour = $today['hours']; } } Setting an Action Attribute in the Action to Make It Available to the Template <p>Hello, world!</p> <?php if ($hour >= 18): ?> <p>Or should I say good evening? It is already <?php echo $hour ?>.</p> <?php endif; ?> The Template Has Direct Access to the Action Attributes
  • 13. Note The template already has access to a few pieces of data without the need of any variable setup in the action. Every template can call methods of the $sf_request , $sf_params , $sf_response , and $sf_user objects. They contain data related to the current request, request parameters, response, and session.
  • 14. You will soon learn how to use them efficiently.
  • 15. Linking to Another Action <a href=&quot;/frontend_dev.php/content/update?name=anonymous&quot;> I never say my name </a> Hyperlinks, the Classic Way <p>Hello, world!</p> <?php if ($hour >= 18): ?> <p>Or should I say good evening? It is already <?php echo $hour ?>.</p> <?php endif; ?> <form method=&quot;post&quot; action=&quot;<?php echo url_for('content/update') ?>&quot;> <label for=&quot;name&quot;>What is your name?</label> <input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; value=&quot;&quot; /> <input type=&quot;submit&quot; value=&quot;Ok&quot; /> <?php echo link_to('I never say my name','content/update?name=anonymous') ?> </form> The link_to() , and url_for() Helpers
  • 16. link_to() helpers // Option argument as an associative array <?php echo link_to('I never say my name', 'content/update?name=anonymous', array( 'class' => 'special_link', 'confirm' => 'Are you sure?', 'absolute' => true )) ?> // Option argument as a string <?php echo link_to('I never say my name', 'content/update?name=anonymous', 'class=special_link confirm=Are you sure? absolute=true') ?> // Both calls output the same => <a class=&quot;special_link&quot; onclick=&quot;return confirm('Are you sure?');&quot; href=&quot;http://localhost/frontend_dev.php/content/update/name/anonymous&quot;> I never say my name</a> Most Helpers Accept an Option Argument
  • 17. Getting Information from the Request <?php class contentActions extends sfActions { // ... public function executeUpdate($request) { $this->name = $request->getParameter('name'); } } Getting Data from the Request Parameter in the Action If there is no data manipulation, use $sf_params object instead in template : <p>Hello, <?php echo $sf_params->get('name') ?>!</p>
  • 18. $_POST , $_GET , or $_REQUEST Usage? Why not use the $_POST , $_GET , or $_REQUEST variables instead? Because then your URLs will be formatted differently (as in http://localhost/articles/europe/france/finance.html, without ? nor =), the usual PHP variables won't work anymore, and only the routing system will be able to retrieve the request parameters. And you may want to add input filtering to prevent malicious code injection, which is only possible if you keep all request parameters in one clean parameter holder.
  • 19. $sf_params is more powerful Or ..... <p>Hello, <?php echo $sf_params->get('name', 'John Doe') ?>!</p> <?php if ($sf_params->has('name')): ?> <p>Hello, <?php echo $sf_params->get('name') ?>!</p> <?php else: ?> <p>Hello, John Doe!</p> <?php endif; ?> Testing the Existence of a Request Parameter in the Template
  • 20. Summary In symfony, pages are composed of an action (a method in the actions/actions.class.php file prefixed with execute) and a template (a file in the templates/ directory, usually ending with Success.php). They are grouped in modules, according to their function in the application. Writing templates is facilitated by helpers, which are functions provided by symfony that return HTML code. And you need to think of the URL as a part of the response, which can be formatted as needed, so you should refrain from using any direct reference to the URL in action naming or request parameter retrieval.
  • 21. Q&A
  • 22. Reference The Definitive Guide to symfony, Fabien Potencier , Apress