Created
December 14, 2011 21:29
-
-
Save objectivehtml/1478635 to your computer and use it in GitHub Desktop.
A better way to fetch EE parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function param($param, $default = FALSE, $boolean = FALSE, $required = FALSE) | |
{ | |
$name = $param; | |
$param = $this->EE->TMPL->fetch_param($param); | |
if($required && !$param) show_error('You must define a "'.$name.'" parameter in the '.__CLASS__.' tag.'); | |
if($param === FALSE && $default !== FALSE) | |
{ | |
$param = $default; | |
} | |
else | |
{ | |
if($boolean) | |
{ | |
$param = strtolower($param); | |
$param = ($param == 'true' || $param == 'yes') ? TRUE : FALSE; | |
} | |
} | |
return $param; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$param = $this->param('entry_id'); //Most basic usage. Fetches entry_id parameter, if it's not set, returns FALSE
$param = $this->param('entry_id', FALSE, FALSE, TRUE); //Requires an entry_id parameter.
$bool_param = $this->param('include_js', FALSE, TRUE); //Fetches a parameter and if 'true' or 'yes', returns TRUE. If not TRUE then returns FALSE
$default_param = $this->param('dynamic', TRUE, TRUE); //Fetches a boolean value but if param is not set, still returns TRUE