SlideShare ist ein Scribd-Unternehmen logo
1 von 17
URL Routing Basics
Overview
Objective
Learn the basics setting up routing in your application with
ProdigyView. This tutorial simulates an MVC.
Requirements
 Understanding of an url
 Installed version of ProdigyView with a database
 An understanding of MVC Design
Estimated Time
15 minutes

                        www.prodigyview.com
Follow Along With Code
               Example
1. Download a copy of the example code at
  www.prodigyview.com/source.

2. Install the system in an environment you feel comfortable
  testing in.

3. Proceed to mvc/helium/config/bootstrap/router.php




                       www.prodigyview.com
What is Routing
Routing is process of selecting a path to send traffic too. In
PHP, url routing is the process of directing traffic to a location
on a website.

Most frameworks and CMS using a front end controller to
control the process of routing. In this tuturial, we are going to
use Helium's routing example.

The first thing we have to do is make sure your server is
configured to handle routing.




                         www.prodigyview.com
Routing - Apache
Depending on your server set up, you can achieve routing
in apache by modifying the .htaccess file in site’s root
location. For this example, copy the code below into your
.htaccess file and the rewrite rule will work.
Routing - Nginx
If you are on a Nginx Server, routing is handled a little
differently. In your sites-available, modify the location section
of your sites configuration.




  Add this to the location for routing
Examples
In ProdigyView, routing is governed by rules. Refer to
helium’s config/bootstrap/router.php for an example of
the rule. Each rule below can correspond to a different
action.




Remember these rules, they will be used throughout this tutorial



                          www.prodigyview.com
Rules
In routing, a rule is when a certain uri matches a rules. The rules can be
exact or general match. Examples are below.
                                     Exact Match
Rule – ‘/user/login’
Will react only if the uri is ‘/user/login’
                                   Variable Match
Rule – ‘/:controller/:action’
Will react to a uri that has two elements. This mean the uri such as
‘/something/random’ will have a match.
These uri will not match with the rule aboe.
‘/something/random/more’ or ‘/something’ .

      Using ‘/:variable_name’ will make the rule match any variable in the uri
Uri and Rules
Examples of uri that will match certain rules are below.
Rules and Your Application
Once a rule is found, is up to your application to handle
the how the rule influences the execution of your code.

The rules in this tutorial were designed for an mvc, but
they can change to fit your application. Our next example
will show helium uses the rule.




                      www.prodigyview.com
Use the rules in application
    Below is Helium’s MVC and how it routes based on the
    rules.
 1. Get the route        2. If the route’s controller and action is not set, use the
                         variables form the uri. Otherwise, use variables in route..




3. Set the default value for the     4. Call the controller based upon the variables
controller and action                above.
Get Route Variable
Taking a closer look at Helium's router, we can see that the
PVRouter::getRouteVariable() method is retrieving a variable.
If the variable is defined in one of our rules and is in the uri, it
will be retrieved.




In this example, if the uri is /posts/view, it matches one of our
rules. Therefore we can retrieve the variable by calling the part of
the rule and assign it to our action in our mvc.

                          www.prodigyview.com
Get Route Variable In
             Controller
We have a way of retrieving our controller and action in
our mvc. But there will be times we need to retrieve other
variables in our application such as an id. Again, we can
use Helium as our example. Proceed to Helium’s post
controller.




                     www.prodigyview.com
Inside the Controller
Look at the beginning of our view method in the the controller.
From the rules we set before, we can retrieve the ID and use it
find data and pass it too our view.
Challenge!
To help better your understanding of routing, complete this
optional challenge.

1. Create a front end controller has multiple actions to execute.
2. In your router, add route route rules.
3. In your front end controller, set up a mapping system that
   executes commands depending on if the rule matches.

4. Run your front end controller and ensure that the correct
   commands are executed based on the route passed.
Review
1. Define route rules with the method
   PVRouter::addRouteRule()

2. Configure your web server (Apache or Nginx) to
   handle rewrite rules

3. Using a string form such as /:controller to define
   variable routes.

4. Use PVRouter::getRouteVariable() to retrieve
   variables from a route.



                      www.prodigyview.com
API Reference
For a better understanding of the PVRouter, check out the
api at the two links below.

PVRouter




                 More Tutorials
For more tutorials, please visit:

http://www.prodigyview.com/tutorials


                       www.prodigyview.com

Weitere ähnliche Inhalte

Andere mochten auch

[D2SF] Naver 오픈 API 가이드
[D2SF] Naver 오픈 API 가이드[D2SF] Naver 오픈 API 가이드
[D2SF] Naver 오픈 API 가이드NAVER D2 STARTUP FACTORY
 
[Tutorial] Diccionario de Naver (Español)
[Tutorial] Diccionario de Naver (Español)[Tutorial] Diccionario de Naver (Español)
[Tutorial] Diccionario de Naver (Español)Nadhia Olivos
 
F3 네이버오픈api만드는매쉬업
F3 네이버오픈api만드는매쉬업F3 네이버오픈api만드는매쉬업
F3 네이버오픈api만드는매쉬업NAVER D2
 
Atm using fingerprint
Atm using fingerprintAtm using fingerprint
Atm using fingerprintAnIsh Kumar
 
Alfabeto coreano en español
Alfabeto coreano en españolAlfabeto coreano en español
Alfabeto coreano en españolStudent
 
Libro de coreano básico
Libro de coreano básicoLibro de coreano básico
Libro de coreano básicoIrving Lee
 
Routing Information Protocol
Routing Information ProtocolRouting Information Protocol
Routing Information ProtocolKashif Latif
 
Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1CAVC
 
Segment Routing & Application Engeering Routing
Segment Routing & Application Engeering RoutingSegment Routing & Application Engeering Routing
Segment Routing & Application Engeering RoutingBertrand Duvivier
 
Tutorial Pembuatan Aplikasi Website Beserta Databasenya
Tutorial Pembuatan Aplikasi Website Beserta DatabasenyaTutorial Pembuatan Aplikasi Website Beserta Databasenya
Tutorial Pembuatan Aplikasi Website Beserta DatabasenyaRCH_98
 

Andere mochten auch (15)

[D2SF] Naver 오픈 API 가이드
[D2SF] Naver 오픈 API 가이드[D2SF] Naver 오픈 API 가이드
[D2SF] Naver 오픈 API 가이드
 
[Tutorial] Diccionario de Naver (Español)
[Tutorial] Diccionario de Naver (Español)[Tutorial] Diccionario de Naver (Español)
[Tutorial] Diccionario de Naver (Español)
 
F3 네이버오픈api만드는매쉬업
F3 네이버오픈api만드는매쉬업F3 네이버오픈api만드는매쉬업
F3 네이버오픈api만드는매쉬업
 
Curso de Coreano Gratuito
Curso de Coreano GratuitoCurso de Coreano Gratuito
Curso de Coreano Gratuito
 
Atm using fingerprint
Atm using fingerprintAtm using fingerprint
Atm using fingerprint
 
Korean1
Korean1Korean1
Korean1
 
Libro
LibroLibro
Libro
 
Alfabeto coreano en español
Alfabeto coreano en españolAlfabeto coreano en español
Alfabeto coreano en español
 
Libro de coreano básico
Libro de coreano básicoLibro de coreano básico
Libro de coreano básico
 
Jason Mdmp Chart
Jason Mdmp ChartJason Mdmp Chart
Jason Mdmp Chart
 
Routing Information Protocol
Routing Information ProtocolRouting Information Protocol
Routing Information Protocol
 
Mdmp Bctp
Mdmp BctpMdmp Bctp
Mdmp Bctp
 
Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1
 
Segment Routing & Application Engeering Routing
Segment Routing & Application Engeering RoutingSegment Routing & Application Engeering Routing
Segment Routing & Application Engeering Routing
 
Tutorial Pembuatan Aplikasi Website Beserta Databasenya
Tutorial Pembuatan Aplikasi Website Beserta DatabasenyaTutorial Pembuatan Aplikasi Website Beserta Databasenya
Tutorial Pembuatan Aplikasi Website Beserta Databasenya
 

Mehr von ProdigyView

Installing Plug-ins
Installing Plug-insInstalling Plug-ins
Installing Plug-insProdigyView
 
Building An Application
Building An ApplicationBuilding An Application
Building An ApplicationProdigyView
 
Installing Applications
Installing ApplicationsInstalling Applications
Installing ApplicationsProdigyView
 
Video Content Management
Video Content ManagementVideo Content Management
Video Content ManagementProdigyView
 
Audio Content Management
Audio Content ManagementAudio Content Management
Audio Content ManagementProdigyView
 
File Content Management
File Content ManagementFile Content Management
File Content ManagementProdigyView
 
Email Configuration
Email ConfigurationEmail Configuration
Email ConfigurationProdigyView
 
HTML5 Tags and Elements Tutorial
HTML5 Tags and Elements TutorialHTML5 Tags and Elements Tutorial
HTML5 Tags and Elements TutorialProdigyView
 
HTML Forms Tutorial
HTML Forms TutorialHTML Forms Tutorial
HTML Forms TutorialProdigyView
 
Html Tags Tutorial
Html Tags TutorialHtml Tags Tutorial
Html Tags TutorialProdigyView
 
Video Conversion PHP
Video Conversion PHPVideo Conversion PHP
Video Conversion PHPProdigyView
 
Sending Email Basics PHP
Sending Email Basics PHPSending Email Basics PHP
Sending Email Basics PHPProdigyView
 
Tools ProdigyView
Tools ProdigyViewTools ProdigyView
Tools ProdigyViewProdigyView
 
Custom Validation PHP
Custom Validation PHPCustom Validation PHP
Custom Validation PHPProdigyView
 
Basic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHPBasic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHPProdigyView
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web CacheProdigyView
 
Javascript And CSS Libraries
Javascript And CSS LibrariesJavascript And CSS Libraries
Javascript And CSS LibrariesProdigyView
 
SQL Prepared Statements Tutorial
SQL Prepared Statements TutorialSQL Prepared Statements Tutorial
SQL Prepared Statements TutorialProdigyView
 

Mehr von ProdigyView (20)

Installing Plug-ins
Installing Plug-insInstalling Plug-ins
Installing Plug-ins
 
Building An Application
Building An ApplicationBuilding An Application
Building An Application
 
Installing Applications
Installing ApplicationsInstalling Applications
Installing Applications
 
Video Content Management
Video Content ManagementVideo Content Management
Video Content Management
 
Audio Content Management
Audio Content ManagementAudio Content Management
Audio Content Management
 
File Content Management
File Content ManagementFile Content Management
File Content Management
 
Email Configuration
Email ConfigurationEmail Configuration
Email Configuration
 
HTML5 Tags and Elements Tutorial
HTML5 Tags and Elements TutorialHTML5 Tags and Elements Tutorial
HTML5 Tags and Elements Tutorial
 
HTML Forms Tutorial
HTML Forms TutorialHTML Forms Tutorial
HTML Forms Tutorial
 
Html Tags Tutorial
Html Tags TutorialHtml Tags Tutorial
Html Tags Tutorial
 
Video Conversion PHP
Video Conversion PHPVideo Conversion PHP
Video Conversion PHP
 
Sending Email Basics PHP
Sending Email Basics PHPSending Email Basics PHP
Sending Email Basics PHP
 
Tools ProdigyView
Tools ProdigyViewTools ProdigyView
Tools ProdigyView
 
Custom Validation PHP
Custom Validation PHPCustom Validation PHP
Custom Validation PHP
 
Basic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHPBasic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHP
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web Cache
 
Javascript And CSS Libraries
Javascript And CSS LibrariesJavascript And CSS Libraries
Javascript And CSS Libraries
 
PHP Libraries
PHP LibrariesPHP Libraries
PHP Libraries
 
SQL Prepared Statements Tutorial
SQL Prepared Statements TutorialSQL Prepared Statements Tutorial
SQL Prepared Statements Tutorial
 
Database Basics
Database BasicsDatabase Basics
Database Basics
 

Kürzlich hochgeladen

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Url Routing Basics Tutorial PHP

  • 2. Overview Objective Learn the basics setting up routing in your application with ProdigyView. This tutorial simulates an MVC. Requirements  Understanding of an url  Installed version of ProdigyView with a database  An understanding of MVC Design Estimated Time 15 minutes www.prodigyview.com
  • 3. Follow Along With Code Example 1. Download a copy of the example code at www.prodigyview.com/source. 2. Install the system in an environment you feel comfortable testing in. 3. Proceed to mvc/helium/config/bootstrap/router.php www.prodigyview.com
  • 4. What is Routing Routing is process of selecting a path to send traffic too. In PHP, url routing is the process of directing traffic to a location on a website. Most frameworks and CMS using a front end controller to control the process of routing. In this tuturial, we are going to use Helium's routing example. The first thing we have to do is make sure your server is configured to handle routing. www.prodigyview.com
  • 5. Routing - Apache Depending on your server set up, you can achieve routing in apache by modifying the .htaccess file in site’s root location. For this example, copy the code below into your .htaccess file and the rewrite rule will work.
  • 6. Routing - Nginx If you are on a Nginx Server, routing is handled a little differently. In your sites-available, modify the location section of your sites configuration. Add this to the location for routing
  • 7. Examples In ProdigyView, routing is governed by rules. Refer to helium’s config/bootstrap/router.php for an example of the rule. Each rule below can correspond to a different action. Remember these rules, they will be used throughout this tutorial www.prodigyview.com
  • 8. Rules In routing, a rule is when a certain uri matches a rules. The rules can be exact or general match. Examples are below. Exact Match Rule – ‘/user/login’ Will react only if the uri is ‘/user/login’ Variable Match Rule – ‘/:controller/:action’ Will react to a uri that has two elements. This mean the uri such as ‘/something/random’ will have a match. These uri will not match with the rule aboe. ‘/something/random/more’ or ‘/something’ . Using ‘/:variable_name’ will make the rule match any variable in the uri
  • 9. Uri and Rules Examples of uri that will match certain rules are below.
  • 10. Rules and Your Application Once a rule is found, is up to your application to handle the how the rule influences the execution of your code. The rules in this tutorial were designed for an mvc, but they can change to fit your application. Our next example will show helium uses the rule. www.prodigyview.com
  • 11. Use the rules in application Below is Helium’s MVC and how it routes based on the rules. 1. Get the route 2. If the route’s controller and action is not set, use the variables form the uri. Otherwise, use variables in route.. 3. Set the default value for the 4. Call the controller based upon the variables controller and action above.
  • 12. Get Route Variable Taking a closer look at Helium's router, we can see that the PVRouter::getRouteVariable() method is retrieving a variable. If the variable is defined in one of our rules and is in the uri, it will be retrieved. In this example, if the uri is /posts/view, it matches one of our rules. Therefore we can retrieve the variable by calling the part of the rule and assign it to our action in our mvc. www.prodigyview.com
  • 13. Get Route Variable In Controller We have a way of retrieving our controller and action in our mvc. But there will be times we need to retrieve other variables in our application such as an id. Again, we can use Helium as our example. Proceed to Helium’s post controller. www.prodigyview.com
  • 14. Inside the Controller Look at the beginning of our view method in the the controller. From the rules we set before, we can retrieve the ID and use it find data and pass it too our view.
  • 15. Challenge! To help better your understanding of routing, complete this optional challenge. 1. Create a front end controller has multiple actions to execute. 2. In your router, add route route rules. 3. In your front end controller, set up a mapping system that executes commands depending on if the rule matches. 4. Run your front end controller and ensure that the correct commands are executed based on the route passed.
  • 16. Review 1. Define route rules with the method PVRouter::addRouteRule() 2. Configure your web server (Apache or Nginx) to handle rewrite rules 3. Using a string form such as /:controller to define variable routes. 4. Use PVRouter::getRouteVariable() to retrieve variables from a route. www.prodigyview.com
  • 17. API Reference For a better understanding of the PVRouter, check out the api at the two links below. PVRouter More Tutorials For more tutorials, please visit: http://www.prodigyview.com/tutorials www.prodigyview.com