Previous Up Next
MVC - Controller phpHtmlLib Framework Caching

Request Classes

The phpHtmlLib Controller

© October 2007, Walter A. Boring IV, Suren Markosian
(phpHtmlLib 3.0.1)

Table of Contents

Request

When using the phpHtmlLib framework and you need to get access to a GET/POST var, the Request object is the proper mechanism to access the variables. The Request object has the capability of filtering out variables that you didn't want in the request or validating the type of each variable. If you register a GET/POST variable with the Request object with a certain type, the Request object will try and validate that the type matches. This can be used to help detect tampering with variabls.

Here are some sample uses of the Request object.

<?php
  //get the $_GET['foo'] variable.
  $var = Request::singleton()->get('foo');

  //was the last request done via ajax?
  $ajax = Request::singleton()->is_ajax();

  //get the target object from the last request
  //the target object is supposed to service the
  //request via the Controller
  $target = Request::singleton()->get_target();

?>

RequestBuilder

The RequestBuilder object is what you would use to generate a normal GET request to a target object via the Controller. It can build a normal url that you inject into the href attribute of an Atag object, or it can build a javascript url that you can place in the onclick attribute.

Here are some samples of using the RequestBuilder

<?php
  //Generate a request to the mvc for the HomePage object.
  $url = RequestBuilder::build_url('HomePage');

  //get a url to the HomePage object including
  //all of the GET vars from the last request made.
  $url = RequestBuilder::build_url_with_request('HomePage');

  //get a url and add a new request variable.
  $url = RequestBuilder::build_url('DownloadPage', array('version' => '3'));
?>
          

By default every url generated will point to the document root's index.php script. If you need the request to go to another controller besides /index.php, then just change the prefix.

<?php
  //we need the next requests to go to /backoffice/index.php
  RequestBuilder::set_prefix('/backoffice/index.php');

  //now get the url to the AdminHomePage target object.
  $url = RequestBuilder::build_url('AdminHomePage');
?>
      

PostRequestBuilder

The PostRequestBuilder object is what you would use to generate a normal POST request to a target object via the Controller. It operates just like the RequestBuilder.

Here are some samples of using the PostRequestBuilder

<?php
  //Generate a request to the mvc for the HomePage object.
  $url = PostRequestBuilder::build_url('HomePage');

  //get a url to the HomePage object including
  //all of the GET vars from the last request made.
  $url = PostRequestBuilder::build_url_with_request('HomePage');

  //get a url and add a new request variable.
  $url = PostRequestBuilder::build_url('DownloadPage', array('version' => '3'));
?>
          

AjaxRequestBuilder

The AjaxRequestBuilder object does the same thing as the RequestBuilder object, but it generates an ajax style urls that call the controller. This requires that the framework/js/ajax.js javascript file be included as well as the framscriptaculous/lib

This class requires that some javascript files be included in the currently loaded page to work.

  • phphtmllib/framework/js/scriptaculous/lib/prototype.js

  • phphtmllib/framework/js/scriptaculous/src/scriptaculous.js

  • phphtmllib/framework/js/ajax.js

  • Here are some samples of using the ajaxRequestBuilder

    <?php
      //Generate a request to the mvc for the HomePage object.
      $url = AjaxRequestBuilder::build_url('HomePage');
    
      //get a url to the HomePage object including
      //all of the GET vars from the last request made.
      $url = AjaxRequestBuilder::build_url_with_request('HomePage');
    
      //get a url and add a new request variable.
      $url = AjaxRequestBuilder::build_url('DownloadPage', array('version' => '3'));
    ?>
              

    AjaxPostRequestBuilder

    The AjaxPostRequestBuilder is the same as the above classes, but it generates a POST ajax request.

    Software license

    phpHtmlLib is released under GNU LGPL

    Previous Up Next
    MVC - Controller phpHtmlLib Framework Caching

    Documentation generated on Thu, 11 Oct 2007 12:05:14 -0700 by phpDocumentor 1.4.0