Dynamic: Difference between revisions
Appearance
m Created page with "<?php // -------------------------------------------------------------------- // testlists class // -------------------------------------------------------------------- class t..." |
m Dynamic & Dep[endant atkListAttribute |
||
| Line 1: | Line 1: | ||
<?php | Values available in list_2 are dependant on value selected in list_1 | ||
<syntaxhighlight lang="php"><?php | |||
// -------------------------------------------------------------------- | // -------------------------------------------------------------------- | ||
| Line 40: | Line 43: | ||
if ($record["list_1"] == "10") | if ($record["list_1"] == "10") | ||
{ | { | ||
// NB These vales could be read from a DB table :) | |||
$optionarray = array("10", "11", "12"); | $optionarray = array("10", "11", "12"); | ||
$valuearray = array("10", "11", "12"); | $valuearray = array("10", "11", "12"); | ||
| Line 46: | Line 50: | ||
if ($record["list_1"] == "20") | if ($record["list_1"] == "20") | ||
{ | { | ||
// NB These vales could be read from a DB table :) | |||
$optionarray = array("20", "21", "22"); | $optionarray = array("20", "21", "22"); | ||
$valuearray = array("20", "21", "22"); | $valuearray = array("20", "21", "22"); | ||
| Line 60: | Line 64: | ||
//------------------------------------------------------------------ | //------------------------------------------------------------------ | ||
?> | ?> | ||
</syntaxhighlight> | |||
Latest revision as of 20:26, 6 February 2014
Values available in list_2 are dependant on value selected in list_1
<?php
// --------------------------------------------------------------------
// testlists class
// --------------------------------------------------------------------
class testlists extends atkNode
{
function testlists()
{
$this -> atkNode("testlists");
$attr_list_1 = &$this -> add(new atklistattribute("list_1",
array("Tens", "Twentys"), array(10, 20)));
$attr_list_1 -> setLoadType(NOLOAD);
$attr_list_1 -> setStorageType(NOSTORE);
$attr_list_1 -> addDependee("list_2");
$attr_list_2 = &$this -> add(new Dynamiclistattribute("list_2",
array(), array()));
$attr_list_2 -> setLoadType(NOLOAD);
$attr_list_2 -> setStorageType(NOSTORE);
}
}
// -------------------------------------------------------------------
// DynamicListAttribute class
// -------------------------------------------------------------------
class DynamicListAttribute extends atkListAttribute
{
function edit($record, $prefix = "", $mode = "")
{
$optionarray = array();
$valuearray = array();
if ($record["list_1"] == "10")
{
// NB These vales could be read from a DB table :)
$optionarray = array("10", "11", "12");
$valuearray = array("10", "11", "12");
}
if ($record["list_1"] == "20")
{
// NB These vales could be read from a DB table :)
$optionarray = array("20", "21", "22");
$valuearray = array("20", "21", "22");
}
$this -> setoptions($optionarray, $valuearray);
return parent::edit($record, $prefix, $mode);
}
}
//------------------------------------------------------------------
?>