OK, here it goes:
if (true)
{
$myVar = $modx->getSomeVar();
}
return $myVar;
$myVar is declared (or is it defined, or both? not sure how that works in php, anyways) in the scope of the "if(true) { }
So,it’s not possible to use it outside those { }
EDIT: Seems not to work as I thought first :-(
///////////////
A simple fix would be to declare it first:
var $myVar;
if (true)
{
$myVar = $modx->getSomeVar();
}
return $myVar;
//////////////////////
Well, if $myVar would be a string or something, this will do:
$myVar = '';
if (true)
{
$myVar = $modx->getSomeVar();
}
return $myVar;
Now, something else to catch:
What if $_GET[’start’] doesn’t exist?
This is nicer, and fixes the warning above codes produces if $_GET[’start’] doesn’t exist:
$start= isset($_GET['start'])? $_GET['start']: 0;
Use the "isset( )" to make sure you reference something that exists.
This doesn’t work neither:
$debug = isset($debug)? $debug : 0;
html_substr($posttext, $minimum_length, $length_offset) {
if($debug) {
echo "HELP";
}
}
$output .= html_substr($posttext, $minimum_length, $length_offset);
Instead, you have to do something like this:
$debug = isset($debug)? $debug : 0;
html_substr($posttext, $minimum_length, $length_offset, $debug) {
if($debug) {
echo "HELP";
}
}
$output .= html_substr($posttext, $minimum_length, $length_offset, $debug );
If someone has a better solution?
This one works actually, but ehm, $sortby = $sortby seems a bit redundant?
if(isset($sortby) && in_array($sortby,$dbfields)) {
$sortby = $sortby;
} else {
$sortby = "createdon";
}
OK, on request, here’s an updated NewsListing snippet. PLEASE test!