2. Overview
Objective
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
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. Router Options
The 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
5. 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
6. Changing Route Actions
Building 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
7. Specify Routes
Similar 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
8. Customize Urls
The 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?
www.prodigyview.com
9. Access Level
Using 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 urls.
1. Set the rule to be the url path 2. Require that the user have an
‘/post/add’ access level of 1 to access this
area
3. If the user does not have the required access
level, redirect them to this url
10. User Roles
Similar 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 2. Require that the user have the
‘/user/admin’ role ‘Admin’
3. If the user does not have the required role,
redirect them to this url
www.prodigyview.com
11. Automatic SSL
If you are developing a site that requires ssl, you might want to
set a rule that being on the page to purchase a product
requires a 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
12. 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 the rule, remove an ssl connection if
one is present
www.prodigyview.com
13. Review
1. Redirects can be added to a rule by defining a redirect
in the options.
2. In an MVC setting, rules can be routes to use a
specific controller and action that is not normally
associated with that route.
3. Rules can be used to block access to a location on the
site with access levels and roles.
4. SSL can be automatically activated or deactivated
depending on a rule.
www.prodigyview.com
14. 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