This post originated from an RSS feed registered with PHP Buzz
by Forum One.
Original Post: Making a custom Request Handler
Feed Title: Syntax Framework
Feed URL: http://blog.syntaxcms.org/rss.php?version=0.91
Feed Description: Finally, a place to answer Syntax questions
Syntax CMS comes with two very flexible Request handlers for routing incoming URLs. Which handler
is used is determined by the first directory in the url, i.e. http://www.example.com/section/
or http://www.example.com/content. Such requests are routed either to the section.php script
( via /section ) or to a capability of a registered module ( via /content ).
For a recent project, I needed to write a new Request handler, primarily to provide pages under a url first level
directory (/resource_centers) but also because I would need to provide a hierarchy of sections as well
as module calls all under one directory.
All a request handler does is tell syntax what php script to run, by returning
the full path to the script It could, therefore, return any sort of output to the browser/client - it
doesn't have to be a web page. These are the basic steps needed to implement your own
custom request handler.,
1. Directing your request
The first step is to route requests using mod_rewrite. You'll need to edit the .htacess file in
your public web documents root and add two rewrite rules.
When a request comes in, syntax looks for a class that extends the Request class. Save the new
file in your private/lib/syntaxcms/Request directory. The filename should be "Resource_centersRequest.class.php",
capitalize the first letter of your directory and append "Request.class.php" to it.
The class definition should look like:
require_once( dirname(_FILE_).'/Request.class.php' );
/**
Custom request class for handling resource centers
/
class Resource_CentersRequest extends Request
{
3. Implement getScript()
Now when syntax finds your request handler, it'll create an instance and try to call
a getScript method. This method takes no input and returns the path to the php script
that should be executed to handle the request. Since it extends the Request class, you
can use the getPathElement method to inspect the url path, 0 is the first element and so on.
You can also use the getVar method to get the value of GET/POST variables.