SlideShare a Scribd company logo
ROUTING IN SYMFONY
Sayed Ahmed
B.Sc. Eng. in Computer Science & Engineering
M. Sc. in Computer Science
Exploring Computing for 14+ years
sayed@justetc.net
http://sayed.justetc.net
URLS
 Symfony has an entire framework dedicated to URL
management:
 the routing framework
 Exposing internal code structure or sensitive
information through URLs is not secure
 Hence, Symfony uses internal URIs and External URLs
 routing manages internal URIs and external URLs
 When a request comes in
 the routing parses the URL
 and converts it to an internal URI
10/8/2011
2
sayed@justetc.net
URLS
 Internal URI
 'job/show?id='.$job->getId()
 The generic pattern for internal URIs is:
 MODULE/ACTION?key=value&key_1=value_1&...
 The url_for() helper converts this internal URI to a
proper URL:
 External URL: /job/show/id/1
 Converting Internal URIs to External URLs
 url_for('@default?module=job&action=show&id='.$job-
>getId())
 url_for('job/show?id='.$job->getId())
10/8/2011
3
sayed@justetc.net
ROUTING CONFIGURATION
 The mapping between internal URIs and external
URLs is done in the routing.yml configuration file:
10/8/2011
4
sayed@justetc.net
ROUTE CUSTOMIZATIONS
For production environment, clear the cache by calling the cache:clear task.
10/8/2011
5
sayed@justetc.net
EXAMPLE: ROUTE CUSTOMIZATION
 /job/sensio-labs/paris-france/1/web-developer
 Pattern:
 /job/:company/:location/:id/:position
 routing.yml
Changes required in the web-page file
10/8/2011
6
sayed@justetc.net
EXAMPLE: ROUTE CUSTOMIZATION
 An internal URI can also be expressed as an array:
10/8/2011
7
sayed@justetc.net
ROUTING AND INPUT VALIDATION
 The routing system has a built-in validation feature
 Each pattern variable can be validated by
 a regular expression
 defined using the requirements entry of a route
definition
10/8/2011
8
sayed@justetc.net
ROUTE CLASS
 Each route defined in routing.yml is internally converted
to an object of class sfRoute
 Can be customized as follows:
 sfRequestRoute
 Can provide by blocking
 DELETE, and PUT http requests
10/8/2011
9
sayed@justetc.net
SHORTENING OF URL_FOR()
 Object Route Class
 Use sfDoctrineRoute
 class: sfDoctrineRoute
url_for('job/show?id='.$job->getId().'&company='.$job->getCompany().
'&location='.$job->getLocation().'&position='.$job->getPosition())
Can be shortened to
url_for(array('sf_route' => 'job_show_user', 'sf_subject' => $job))
Or
url_for('job_show_user', $job)
10/8/2011
10
sayed@justetc.net
MAKE THE URL LOOK PRETTY
 Convert
 http://www.jobeet.com.localhost/frontend_dev.php/job/S
ensio+Labs/Paris%2C+France/1/Web+Developer
 To
 http://www.jobeet.com.localhost/frontend_dev.php/job/se
nsio-labs/paris-france/1/web-developer
10/8/2011
11
sayed@justetc.net
10/8/2011
12
sayed@justetc.net
CHECK THE ROUTING
10/8/2011
13
sayed@justetc.net
ROUTING IN ACTIONS AND TEMPLATES
 Some symfony helpers take an internal URI as an
argument,
 link_to() for example
 <?php echo link_to($job->getPosition(), 'job_show_user',
$job) ?>
 Output
 <a href="/job/sensio-labs/paris-france/1/web-developer">Web
Developer</a>
 Generate absolute URL
 url_for('job_show_user', $job, true);
 link_to($job->getPosition(), 'job_show_user', $job, true);
 Generate url from action
 $this->redirect($this->generateUrl('job_show_user', $job));
10/8/2011
14
sayed@justetc.net
THE "REDIRECT" METHODS FAMILY
 redirect()
 redirectIf()
 redirectUnless()
10/8/2011
15
sayed@justetc.net
COLLECTION ROUTE CLASS
The job route above is really just a shortcut that automatically generates
seven sfDoctrineRoute routes: job, job_new, job_create, job_edit, job_update,
job_delete, job_show
10/8/2011
16
sayed@justetc.net
ROUTE DEBUGGING
 The app:routes task outputs all the routes for a
given application:
 $ php symfony app:routes frontend
 $ php symfony app:routes frontend job_edit
 Produces more debugging information
10/8/2011
17
sayed@justetc.net
DEFAULT ROUTES
 It is a good practice to define routes for all your
URLs
10/8/2011
18
sayed@justetc.net
REFERENCES
 http://www.symfony-project.org/jobeet/1_4/Doctrine/en/
10/8/2011
19
sayed@justetc.net

More Related Content

Similar to Routing in symfony

AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
Eyal Vardi
 
How to build an AngularJS backend-ready app WITHOUT BACKEND
How to build an AngularJS backend-ready app WITHOUT BACKEND How to build an AngularJS backend-ready app WITHOUT BACKEND
How to build an AngularJS backend-ready app WITHOUT BACKEND
Enrique Oriol Bermúdez
 
OWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP ProgrammersOWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP Programmers
rjsmelo
 
Android networking-2
Android networking-2Android networking-2
Android networking-2
Aravindharamanan S
 
Aurelia Meetup Paris
Aurelia Meetup ParisAurelia Meetup Paris
Aurelia Meetup Paris
Ahmed Radjdi
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
Nitin Giri
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
Pratchaya Suputsopon
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
Eliran Eliassy
 
Http and REST APIs.
Http and REST APIs.Http and REST APIs.
Http and REST APIs.
Rahul Tanwani
 
Node.js server-side rendering
Node.js server-side renderingNode.js server-side rendering
Node.js server-side rendering
The Software House
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
Eyal Vardi
 
A Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed ApplicationA Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed Application
David Hoerster
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
Ran Wahle
 
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosAngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
Learnimtactics
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
Gregor Woiwode
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
Chris Tankersley
 

Similar to Routing in symfony (20)

AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
How to build an AngularJS backend-ready app WITHOUT BACKEND
How to build an AngularJS backend-ready app WITHOUT BACKEND How to build an AngularJS backend-ready app WITHOUT BACKEND
How to build an AngularJS backend-ready app WITHOUT BACKEND
 
OWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP ProgrammersOWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP Programmers
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
 
Android networking-2
Android networking-2Android networking-2
Android networking-2
 
Aurelia Meetup Paris
Aurelia Meetup ParisAurelia Meetup Paris
Aurelia Meetup Paris
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
Http and REST APIs.
Http and REST APIs.Http and REST APIs.
Http and REST APIs.
 
Node.js server-side rendering
Node.js server-side renderingNode.js server-side rendering
Node.js server-side rendering
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
 
A Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed ApplicationA Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed Application
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosAngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
 

More from Sayed Ahmed

Workplace, Data Analytics, and Ethics
Workplace, Data Analytics, and EthicsWorkplace, Data Analytics, and Ethics
Workplace, Data Analytics, and Ethics
Sayed Ahmed
 
Python py charm anaconda jupyter installation and basic commands
Python py charm anaconda jupyter   installation and basic commandsPython py charm anaconda jupyter   installation and basic commands
Python py charm anaconda jupyter installation and basic commands
Sayed Ahmed
 
[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework
Sayed Ahmed
 
Sap hana-ide-overview-nodev
Sap hana-ide-overview-nodevSap hana-ide-overview-nodev
Sap hana-ide-overview-nodev
Sayed Ahmed
 
Invest wisely
Invest wiselyInvest wisely
Invest wisely
Sayed Ahmed
 
Will be an introduction to
Will be an introduction toWill be an introduction to
Will be an introduction to
Sayed Ahmed
 
Whm and cpanel overview hosting control panel overview
Whm and cpanel overview   hosting control panel overviewWhm and cpanel overview   hosting control panel overview
Whm and cpanel overview hosting control panel overview
Sayed Ahmed
 
Web application development using zend framework
Web application development using zend frameworkWeb application development using zend framework
Web application development using zend framework
Sayed Ahmed
 
Web design and_html_part_3
Web design and_html_part_3Web design and_html_part_3
Web design and_html_part_3
Sayed Ahmed
 
Web design and_html_part_2
Web design and_html_part_2Web design and_html_part_2
Web design and_html_part_2
Sayed Ahmed
 
Web design and_html
Web design and_htmlWeb design and_html
Web design and_html
Sayed Ahmed
 
Visual studio ide shortcuts
Visual studio ide shortcutsVisual studio ide shortcuts
Visual studio ide shortcuts
Sayed Ahmed
 
Virtualization
VirtualizationVirtualization
Virtualization
Sayed Ahmed
 
User interfaces
User interfacesUser interfaces
User interfaces
Sayed Ahmed
 
Unreal
UnrealUnreal
Unreal
Sayed Ahmed
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfony
Sayed Ahmed
 
Telerik this is sayed
Telerik this is sayedTelerik this is sayed
Telerik this is sayed
Sayed Ahmed
 
System analysis and_design
System analysis and_designSystem analysis and_design
System analysis and_design
Sayed Ahmed
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
Sayed Ahmed
 
Story telling and_narrative
Story telling and_narrativeStory telling and_narrative
Story telling and_narrative
Sayed Ahmed
 

More from Sayed Ahmed (20)

Workplace, Data Analytics, and Ethics
Workplace, Data Analytics, and EthicsWorkplace, Data Analytics, and Ethics
Workplace, Data Analytics, and Ethics
 
Python py charm anaconda jupyter installation and basic commands
Python py charm anaconda jupyter   installation and basic commandsPython py charm anaconda jupyter   installation and basic commands
Python py charm anaconda jupyter installation and basic commands
 
[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework
 
Sap hana-ide-overview-nodev
Sap hana-ide-overview-nodevSap hana-ide-overview-nodev
Sap hana-ide-overview-nodev
 
Invest wisely
Invest wiselyInvest wisely
Invest wisely
 
Will be an introduction to
Will be an introduction toWill be an introduction to
Will be an introduction to
 
Whm and cpanel overview hosting control panel overview
Whm and cpanel overview   hosting control panel overviewWhm and cpanel overview   hosting control panel overview
Whm and cpanel overview hosting control panel overview
 
Web application development using zend framework
Web application development using zend frameworkWeb application development using zend framework
Web application development using zend framework
 
Web design and_html_part_3
Web design and_html_part_3Web design and_html_part_3
Web design and_html_part_3
 
Web design and_html_part_2
Web design and_html_part_2Web design and_html_part_2
Web design and_html_part_2
 
Web design and_html
Web design and_htmlWeb design and_html
Web design and_html
 
Visual studio ide shortcuts
Visual studio ide shortcutsVisual studio ide shortcuts
Visual studio ide shortcuts
 
Virtualization
VirtualizationVirtualization
Virtualization
 
User interfaces
User interfacesUser interfaces
User interfaces
 
Unreal
UnrealUnreal
Unreal
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfony
 
Telerik this is sayed
Telerik this is sayedTelerik this is sayed
Telerik this is sayed
 
System analysis and_design
System analysis and_designSystem analysis and_design
System analysis and_design
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
 
Story telling and_narrative
Story telling and_narrativeStory telling and_narrative
Story telling and_narrative
 

Recently uploaded

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 

Recently uploaded (20)

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 

Routing in symfony

  • 1. ROUTING IN SYMFONY Sayed Ahmed B.Sc. Eng. in Computer Science & Engineering M. Sc. in Computer Science Exploring Computing for 14+ years sayed@justetc.net http://sayed.justetc.net
  • 2. URLS  Symfony has an entire framework dedicated to URL management:  the routing framework  Exposing internal code structure or sensitive information through URLs is not secure  Hence, Symfony uses internal URIs and External URLs  routing manages internal URIs and external URLs  When a request comes in  the routing parses the URL  and converts it to an internal URI 10/8/2011 2 sayed@justetc.net
  • 3. URLS  Internal URI  'job/show?id='.$job->getId()  The generic pattern for internal URIs is:  MODULE/ACTION?key=value&key_1=value_1&...  The url_for() helper converts this internal URI to a proper URL:  External URL: /job/show/id/1  Converting Internal URIs to External URLs  url_for('@default?module=job&action=show&id='.$job- >getId())  url_for('job/show?id='.$job->getId()) 10/8/2011 3 sayed@justetc.net
  • 4. ROUTING CONFIGURATION  The mapping between internal URIs and external URLs is done in the routing.yml configuration file: 10/8/2011 4 sayed@justetc.net
  • 5. ROUTE CUSTOMIZATIONS For production environment, clear the cache by calling the cache:clear task. 10/8/2011 5 sayed@justetc.net
  • 6. EXAMPLE: ROUTE CUSTOMIZATION  /job/sensio-labs/paris-france/1/web-developer  Pattern:  /job/:company/:location/:id/:position  routing.yml Changes required in the web-page file 10/8/2011 6 sayed@justetc.net
  • 7. EXAMPLE: ROUTE CUSTOMIZATION  An internal URI can also be expressed as an array: 10/8/2011 7 sayed@justetc.net
  • 8. ROUTING AND INPUT VALIDATION  The routing system has a built-in validation feature  Each pattern variable can be validated by  a regular expression  defined using the requirements entry of a route definition 10/8/2011 8 sayed@justetc.net
  • 9. ROUTE CLASS  Each route defined in routing.yml is internally converted to an object of class sfRoute  Can be customized as follows:  sfRequestRoute  Can provide by blocking  DELETE, and PUT http requests 10/8/2011 9 sayed@justetc.net
  • 10. SHORTENING OF URL_FOR()  Object Route Class  Use sfDoctrineRoute  class: sfDoctrineRoute url_for('job/show?id='.$job->getId().'&company='.$job->getCompany(). '&location='.$job->getLocation().'&position='.$job->getPosition()) Can be shortened to url_for(array('sf_route' => 'job_show_user', 'sf_subject' => $job)) Or url_for('job_show_user', $job) 10/8/2011 10 sayed@justetc.net
  • 11. MAKE THE URL LOOK PRETTY  Convert  http://www.jobeet.com.localhost/frontend_dev.php/job/S ensio+Labs/Paris%2C+France/1/Web+Developer  To  http://www.jobeet.com.localhost/frontend_dev.php/job/se nsio-labs/paris-france/1/web-developer 10/8/2011 11 sayed@justetc.net
  • 14. ROUTING IN ACTIONS AND TEMPLATES  Some symfony helpers take an internal URI as an argument,  link_to() for example  <?php echo link_to($job->getPosition(), 'job_show_user', $job) ?>  Output  <a href="/job/sensio-labs/paris-france/1/web-developer">Web Developer</a>  Generate absolute URL  url_for('job_show_user', $job, true);  link_to($job->getPosition(), 'job_show_user', $job, true);  Generate url from action  $this->redirect($this->generateUrl('job_show_user', $job)); 10/8/2011 14 sayed@justetc.net
  • 15. THE "REDIRECT" METHODS FAMILY  redirect()  redirectIf()  redirectUnless() 10/8/2011 15 sayed@justetc.net
  • 16. COLLECTION ROUTE CLASS The job route above is really just a shortcut that automatically generates seven sfDoctrineRoute routes: job, job_new, job_create, job_edit, job_update, job_delete, job_show 10/8/2011 16 sayed@justetc.net
  • 17. ROUTE DEBUGGING  The app:routes task outputs all the routes for a given application:  $ php symfony app:routes frontend  $ php symfony app:routes frontend job_edit  Produces more debugging information 10/8/2011 17 sayed@justetc.net
  • 18. DEFAULT ROUTES  It is a good practice to define routes for all your URLs 10/8/2011 18 sayed@justetc.net