|
BuiltInDatasources
Built in DataSources simplify $_GET and $_POST
ContentsIntroductiontgsf makes several built-in singleton datasource objects available to you. These are exposed using global, uppercase, procedural functions.
Using these is not required, but their use will simplify your development efforts considerably. Working with the GET and POST datasourcesTo 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 datasourcePlease view the CLI documentation page. Working with the URL datasourcePlease view the URL documentation page. |
► Sign in to add a comment