Support for collection key mapping
This commit is contained in:
parent
da9d179d9f
commit
90bd728d81
31
manual/codes/Basic Components - Collection - Key mapping.php
Normal file
31
manual/codes/Basic Components - Collection - Key mapping.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// mapping id column
|
||||
|
||||
$user = new User();
|
||||
|
||||
$user->setAttribute(Doctrine::ATTR_COLL_KEY, 'id');
|
||||
|
||||
// now user collections will use the values of
|
||||
// id column as element indexes
|
||||
|
||||
$users = $user->getTable()->findAll();
|
||||
|
||||
foreach($users as $id => $user) {
|
||||
print $id . $user->name;
|
||||
}
|
||||
|
||||
// mapping name column
|
||||
|
||||
$user = new User();
|
||||
|
||||
$user->setAttribute(Doctrine::ATTR_COLL_KEY, 'name');
|
||||
|
||||
// now user collections will use the values of
|
||||
// name column as element indexes
|
||||
|
||||
$users = $user->getTable()->findAll();
|
||||
|
||||
foreach($users as $name => $user) {
|
||||
print $name . $user->type;
|
||||
}
|
||||
?>
|
@ -0,0 +1,3 @@
|
||||
Sometimes you may not want to use normal indexing for collection elements. For example in
|
||||
some cases mapping primary keys as collection keys might be useful. The following example
|
||||
demonstrates how this can be achieved.
|
@ -138,6 +138,7 @@ $menu = array("Getting started" =>
|
||||
"Saving the collection",
|
||||
"Deleting collection",
|
||||
//"Fetching strategies",
|
||||
"Key mapping",
|
||||
"Loading related records",
|
||||
"Collection expanding",
|
||||
),
|
||||
@ -366,12 +367,12 @@ $menu = array("Getting started" =>
|
||||
if( ! file_exists("docs/$title - $k - $v2.php")) {
|
||||
$missing[0]++;
|
||||
$str .= " [ <font color='red'>doc</font> ] ";
|
||||
//touch("docs/$title - $k - $v2.php");
|
||||
touch("docs/$title - $k - $v2.php");
|
||||
}
|
||||
if( ! file_exists("codes/$title - $k - $v2.php")) {
|
||||
$missing[1]++;
|
||||
$str .= " [ <font color='red'>code</font> ] ";
|
||||
//touch("codes/$title - $k - $v2.php");
|
||||
touch("codes/$title - $k - $v2.php");
|
||||
|
||||
}
|
||||
|
||||
@ -448,27 +449,28 @@ $menu = array("Getting started" =>
|
||||
if(isset($ex[1])) {
|
||||
$name = implode(" - ", $stack);
|
||||
|
||||
print "<b class='title'>".$paths[$curr]."</b><hr>";
|
||||
print "<a name='$path'><b class='title'>".$paths[$curr]."</b></a><hr>";
|
||||
|
||||
$n = $numbers;
|
||||
|
||||
$o = $paths[$n[0]];
|
||||
$s = implode(".", array($n[0], $n[1]));
|
||||
$o2 = $paths[$s];
|
||||
$numpath = implode(".", array($n[0], $n[1]));
|
||||
$o2 = $paths[$numpath];
|
||||
|
||||
$value = $menu[$o];
|
||||
if( ! is_array($value))
|
||||
if( ! is_array($value))
|
||||
exit;
|
||||
|
||||
|
||||
|
||||
if(in_array($o2, $value)) {
|
||||
render_block($name);
|
||||
} else {
|
||||
} else {
|
||||
$value = $menu[$o][$o2];
|
||||
|
||||
if(is_array($value)) {
|
||||
foreach($value as $k => $title) {
|
||||
print "<br \><b class='title'>".$title."</b><hr style='height: 1px' \>";
|
||||
$numpath2 = $numpath . '.' . ($k + 1);
|
||||
print "<br \><a name='".$numpath2."'><b class='title'>".$title."</b></a><hr style='height: 1px' \>";
|
||||
|
||||
$s = $name." - ".$title;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user