The Artima Developer Community
Sponsored Link

PHP Buzz Forum
Making a custom Request Handler

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Forum One

Posts: 118
Nickname: forumone
Registered: Sep, 2004

Forum One is consulting firm specializing in helping non-profits improve their online presence.
Making a custom Request Handler Posted: Dec 22, 2004 2:10 PM
Reply to this message Reply

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
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Forum One
Latest Posts From Syntax Framework

Advertisement

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.

RewriteRule ^resource_centers/(.+)  /load.php?navtype=resource_center&request=$1 [L,QSA]
RewriteRule ^resource_centers/?     /load.php?navtype=resource_center&request=$1 [L,QSA]

2. A class to handle it

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.

Read: Making a custom Request Handler

Topic: PHP and Apache 2 Slashdotted Previous Topic   Next Topic Topic: Setting Up PHP 5 Under Suse 9.1

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use