cakephp2-php8/libs/controllers/templates/scaffolds/show.thtml
phpnut 1dce095546 merging changes from sandboxes
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@856 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-09-17 02:22:07 +00:00

150 lines
No EOL
4.8 KiB
Text

<?php
$modelName = Inflector::singularize($this->name);
$modelKey = Inflector::underscore($modelName);
$registry = ClassRegistry::getInstance();
?>
<dl>
<?php foreach( $fieldNames as $field=>$value ) {
echo "<dt>".$value['prompt']."</dt>";
if( isset( $value['foreignKey'] ) ) {
$otherModelObject = $registry->getObject($value['model']);
$displayField = $otherModelObject->getDisplayField();
$displayText = $data[$value['model']][ $displayField ];
if( !empty($data[$modelKey][$field]))
{
echo "<dd>".$html->linkTo($displayText, '/'.Inflector::underscore($value['controller']).'/show/'.$data[$modelKey][ $field ] )."</dd>";
}
else
{
echo "<dd>&nbsp;</dd>";
}
}
else
{
// this is just a plain old field.
if( !empty($data[$modelKey][$field]))
{
echo "<dd>".$data[$modelKey][$field]."</dd>";
}
else
{
echo "<dd>&nbsp;</dd>";
}
}
}
?>
</dl>
<ul class='actions'>
<?php
echo "<li>".$html->linkTo('Edit '.Inflector::humanize($modelKey), '/'.$this->viewPath.'/edit/'.$data[$modelKey]['id'])."</li>";
echo "<li>".$html->linkTo('Delete '.Inflector::humanize($modelKey), '/'.$this->viewPath.'/destroy/'.$data[$modelKey]['id'])."</li>";
foreach( $fieldNames as $field=>$value ) {
if( isset( $value['foreignKey'] ) )
{
echo "<li>".$html->linkTo( "View ".Inflector::humanize($value['controller']), "/".Inflector::underscore($value['controller'])."/show/".$data[Inflector::singularize($params['controller'])][$field] )."</li>";
}
}
?>
</ul>
<!--hasOne relationships -->
<?php
$objModel = $registry->getObject($modelName);
foreach ($objModel->_oneToOne as $relation)
{
list($table, $field, $value) = $relation;
$otherModelName = Inflector::singularize($table);
echo "<div class='related'><H2>Related ".Inflector::humanize($otherModelName)."</H2><br/><br/>";
echo "<dl>";
if( isset($data[$otherModelName]) && is_array($data[$otherModelName]) )
{
foreach( $data[$otherModelName] as $field=>$value )
{
echo "<dt>".Inflector::humanize($field)."</dt>";
if( !empty($value) )
{
echo "<dd>".$value."</dd>";
} else {
echo "<dd>&nbsp;</dd>";
}
}
}
echo "</dl>";
echo "<ul class='actions'><li>".$html->linkTo('Edit '.Inflector::humanize($otherModelName),"/".Inflector::underscore($table)."/edit/{$data[$otherModelName]['id']}")."</li></ul></div>";
}
?>
<!-- HAS MANY AND HASANDBELONGSTOMANY -->
<?php
$relations = array();
foreach( $objModel->_oneToMany as $relation )
{
$relations[] = $relation;
} // end loop through onetomany relations.
foreach( $objModel->_manyToMany as $relation )
{
$relations[] = $relation;
} // end loop through manytomany relations.
foreach( $relations as $relation )
{
list($table, $field, $value) = $relation;
$count = 0;
$otherModelName = Inflector::singularize($table);
echo "<div class='related'><H2>Related ".Inflector::humanize($table)."</H2><br/><br/>";
if( isset($data[$table]) && is_array($data[$table]) )
{
?>
<table class="inav" cellspacing="0">
<tr>
<?php // Loop through and create the header row.
// find a row that matches this title.
$bFound = false;
foreach( $data[$table][0] as $column=>$value ) {
echo "<th>".Inflector::humanize($column)."</th>";
}
?>
<th>Actions</th>
</tr>
<?php
// now find all matching rows
foreach( $data[$table] as $row )
{
echo "<tr>";
foreach( $row as $column=>$value )
{
echo "<td>".$value."</td>";
}
?>
<td class="listactions"><?php echo $html->linkTo('View',"/".Inflector::underscore($table)."/show/{$row['id']}/")?>
<?php echo $html->linkTo('Edit',"/".Inflector::underscore($table)."/edit/{$row['id']}/")?>
<?php echo $html->linkTo('Delete',"/".Inflector::underscore($table)."/destroy/{$row['id']}/")?>
</td>
<?php
echo "</tr>";
}
}
?>
</table>
<ul class="actions">
<?php
// add a link to create a new relation.
echo "<li>".$html->linkTo('New '.Inflector::humanize($otherModelName),"/".Inflector::underscore($table)."/new/")."</li>";
// echo "<li>".$html->linkTo( "View ".Inflector::humanize($table), "/".Inflector::underscore($table)."/list/".$modelName."/".$data[$modelName]['id'])."</li>";
?>
</ul></div>
<?php } // end loop through relations
?>