My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
BuiltInDatasources  
Built in DataSources simplify $_GET and $_POST
Updated Mar 23, 2010 by treehousetim@gmail.com

Contents

Introduction

tgsf makes several built-in singleton datasource objects available to you. These are exposed using global, uppercase, procedural functions.

  • GET()
  • POST()
  • URL() non singleton - uses global function to return new instance
  • CLI()

Using these is not required, but their use will simplify your development efforts considerably.

Working with the GET and POST datasources

To start off with, let's explore how to use the GET and POST data sources. These are special types of data sources due to the way that PHP handles GET and POST variables.

GET and POST are implemented as singleton classes along with a corresponding uppercase function name to get the singleton instance.

So, you can do this in your scripts:

<?php

if ( POST()->dataPresent )
{
    // logic here
}

if ( GET()->dataPresent )
{
    // logic here
}

Working with Get or Post data is simple:

<?php
$userModel = load_model( 'user' );

if ( POST()->dataPresent && POST()->exists( 'user_id' ) )
{
    $record = $userModel->fetchById( POST()->user_id );
    // work with record here.
}

Keep in mind that GET() and POST() do not allow modifying their contents. Using ->setVar on GET() or POST() datasources will cause an exception to be thrown. You should clone if you need to modify.

<?php
// will cause an exception
GET()->setVar( 'user_id', 123 );

// how to do it
$ds = clone GET();
$ds->setVar( 'user_id', 123 );
?>

Working with the CLI datasource

Please view the CLI documentation page.

Working with the URL datasource

Please view the URL documentation page.


Sign in to add a comment
Powered by Google Project Hosting