Download - URL Routing Options and Customization PHP
OverviewObjective
Customize and control actions of a route based on rules and the options associated with those rules.
Requirements
Understanding of an url
Installed version of ProdigyView with a database
An understanding of MVC Design
Understanding the route rules, read Routing Basics tutorial.
Understanding of user roles and user access levels
Estimated Time
10 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
Router OptionsThe router has a list of options in it that can change how your site functions depending on the rule and options associated with the rule. These options include:
Access Level
User Roles
Redirect
SSL
Changing Controllers and Actions
www.prodigyview.com
Redirects
If a url matches a specified criteria, a redirect can direct the user to another page on the site or an external site. Redirects are great for closing off sections of your site or shortening urls.
1. If the url is ‘www.example.com/users/login’
2. Redirect to ‘www.example.com/login’
www.prodigyview.com
Changing Route ActionsBuilding upon the last example, the redirect sends us to www.example.com/login page, which has no controller or action. Below we are going to set a rule, if the url is /login, then to specify which controller and action to call.
1. If url path is ‘/users/login’, redirect to url ‘/login’
2. If the url is ‘/login’, use the controller users and the action login
Specify RoutesSimilar to changing routes, we can specify completely new routes based on the rules of an url
1. If the url path is ‘/rss’
2. Route to the controller post and set the action to rss
www.prodigyview.com
Customize UrlsThe previous slides show how to shorten urls and also customize how your application will act based on the urls. Based on the past example, can you tell what is happening below?
Access LevelUsing the User Manager that comes with ProdigyView, every user has an access level. Using that access level, we can restrict a user’s access to certain with the access level.
1. Set the rule to be the url path ‘/post/add’
2. Require that the user have an access level of 1 to access this area
3. If the user does not have the required access level, redirect them to this url
User RolesSimilar to access levels, users can be restricted to certain areas based on their roles, another way of easily implementing access control on your site.
1. Set the rule to be the url path ‘/user/admin’
2. Require that the user have the role ‘Admin’
3. If the user does not have the required role, redirect them to this url
www.prodigyview.com
Automatic SSLIf you are developing a site that requires ssl, you might want to require that being on the page to purchase a product that an ssl certificate is to be using. This is very easy to implement using the route options.
1. Set the rule to be the url path /purchase
2. If path matches rule, force an ssl connection
Deactivate SSL
In other instances, you might be to ensure that an ssl connection is not used, no matter what the circumstances are.
1. Set the rule to be the url path ‘/logout’
2. If path matches rule, remove an ssl connection if one is present
www.prodigyview.com
API ReferenceFor a better understanding of the PVRouter, check out the api at the two links below.
PVRouter
www.prodigyview.com
More Tutorials
For more tutorials, please visit:
http://www.prodigyview.com/tutorials