Custom ['_Link']

13 posts by 4 authors in: Forums > CMS Builder
Last Post: April 27, 2010   (RSS)

By aev - April 27, 2010

Dave,

this was even more interesting than the original tip! This way of using references will be very useful as we often loop through cmsb arrays changing or adding values.

But doesn't the last unset clear the referenced variable as well as the local pointer ($record)?

-aev-

Re: [aev] Custom ['_Link']

By Dave - April 27, 2010

Ahh, yes. Good question. Once your done with your reference variable you want to "unset" the reference so future use of that variable ($record) won't modify the data it was "pointing" at. See: http://www.php.net/manual/en/language.references.unset.php

Unset only clears the "pointer" as shown:

$a = "hello";
$b = &$a; // b is now a reference (pointer) to $a
$b = "world";
unset($b); // unsets $b only
print $a; // prints "world";
print $b; // produces error: Undefined variable: b
exit;


You can use this generic code for adding or changing values in a record list:
// create custom _link values
foreach (array_keys($newsRecords) as $index) {
$record = &$newsRecords[$index];

// ... modify record here ...

unset($record);
}


Hope that helps!
Dave Edis - Senior Developer
interactivetools.com