lost password?

home
•  xaraya +
•  rails
•  django
•  webdev
•  xamp
•  musings

rss
Tag this page
   

» Blogs that link here
last modified: Oct 05, 2006
(first posted: Jun 25, 2006)
(2457 Reads)
keywords: redirect url validation xarvarfetch
Permalink

Accessing URL details

Summary of the various xaraya api for getting info on the current URL

Current Page

$url = xarServerGetCurrentURL()

Returns the current page URL. Optionally replace some components (see below)

 

$url = xarServerGetCurrentURL( $args = array(), $generateXMLURL = NULL, $target = NULL )

Returns the current page URL. Optionally replace some components.

* @param args array additional parameters to be added to/replaced in the URL (e.g. theme, ...)
* @param generateXMLURL boolean over-ride Server default setting for generating XML URLs (true/false/NULL)
* @param target string add a 'target' component to the URL

Examples:

$url = xarServerGetCurrentURL();
returns "http://www.mysite.com/news/123" (with short url's enabled and index.php removed)

$url = xarServerGetCurrentURL( array('phase'=>'2') )
returns "http://www.mysite.com/news/123?phase=2"

$url = xarServerGetCurrentURL( NULL, NULL, "abc" )
returns "http://www.mysite.com/news/123#abc"

 

$server = xarServerGetHost()

Returns current server name, e.g. "www.mysite.com". Constructed from HTTP_HOST, or HTTP_SERVER:HTTP_PORT

 

$http = xarServerGetProtocol()

Returns either "http" or "https"

 

$url = xarServerGetBaseURL()

Returns the Xaraya base URL, e.g. "http://www.mysite.com/index.php"

 

Getting Get Vars

$info = xarRequestGetInfo()

get current module, fn type, and function

[0 ] = module name ('articles')

[1] = type ('user', 'admin')

[2] = function ('view')

 

$value = xarRequestGetVar( 'xxx' )

get value of a get var 'xxx'

 

xarVarFetch

$ret = xarVarFetch( 'name', 'validation', $var, default[, flags[, prep]] )

like xarRequestGetVar but does the validation stuff. This is my most common usage, for more see article: http://it-works.ch/index.php?module=articles&func=display&ptid=28&catid=8&aid=37

Where:

name - string name of the get or post variable

validation - type checking, possible values: 'int', 'str', 'checkbox', 'array',

xaraya comes with a ton of different validators you can use

advanced validation examples

'int:1:100' integer in range 1 to 100

 

For details on validation rules, see http://www.xaraya.com/index.php/documentation/163   

var - php variable to assign the value

default - default value if 'name' isn't found

flags -

(none) - required, raise exception if not in post or get

XARVAR_NOT_REQUIRED - if not present, use the default value

XARVAR_DONT_SET - if there is an existing value, use it

other flags also available.

prep - optional flags can do a bit of processing on the data, includes XARVAR_PREP_FOR_DISPLAY, XAR_VAR_PREP_FOR_HTML, and XARVAR_PREP_TRIM

ret - return value, is value assigned to $var, or null if error

 

Examples:

if(!xarVarFetch('id', 'int', $id, 0, XARVAR_NOT_REQUIRED)) {return;}
if (!xarVarFetch('reassign', 'checkbox',  $reassign, false, XARVAR_NOT_REQUIRED)) {return;} 
    if (!xarVarFetch('colors', 'array',  $colors, array(), XARVAR_NOT_REQUIRED)) {return;} 

 

Redirect, Referer, etc.

xarResponseRedirect( $redirectURL )

Redirect to the $redirectURL

 

$truefalse = xarRequestIsLocalReferer()

Returns true if this is a local referal

 

Constructing a URL

See xarServerGetCurrentURL above.

 

$url = xarModUrl( $modName, $modType, $funcName, $args )

$url = xarModURL($modName = NULL, $modType = 'user', $funcName = 'main', $args = array(), $generateXMLURL = NULL, $fragment = NULL, $entrypoint = array())

Create a Xaraya URL.

* @global xarMod_generateShortURLs bool
* @global xarMod_generateXMLURLs bool
* @param modName string registered name of module
* @param modType string type of function
* @param funcName string module function
* @param string fragment document fragment target (e.g. somesite.com/index.php?foo=bar#target)
* @param args array of arguments to put on the URL
* @param entrypoint array of arguments for different entrypoint than index.php
* @return mixed absolute URL for call, or false on failure

 

$content = xarModFunc( $modName, $modType = 'user', $funcName = 'main', $args = array() )

Not exactly fits in this article topic, but included here anyway. Processes the xar module function, runs it through its template, and returns the content in a string for display in the current template.

Example:

<xar:set name="stuff">xarModFunc('articles','user','display',array('aid'=>$aid))</xar:set>
#$stuff#

 

$results = xarModAPIFunc($modName, $modType = 'user', $funcName = 'main', $args = array(), $throwException = 1)

well, if i'm going to include xarModFunc, I might as well include this one too, now we're really off topic :)

* @param modName string registered name of module
* @param modType string type of function to run
* @param funcName string specific function to run
* @param args array arguments to pass to the function
* @param throwException boolean optional flag to throw an exception if the function doesn't exist or not (default = 1)
* @return mixed The output of the function, or false on failure
* @raise BAD_PARAM, MODULE_FUNCTION_NOT_EXIST

 

There are no comments attached to this item.

Post a new comment

How many days in a week?

Name :