Merging fixes and enhancements into trunk

Revision: [1862]
Cleaning up scaffold views

Revision: [1861]
Added fix to scaffold when setting more than one 1 : 1 associations.

Revision: [1860]
Adding patch for Ticket #314

Revision: [1859]
Fixing Ticket #311

Revision: [1858] [1857]

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1863 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-01-25 22:40:17 +00:00
parent 26d7620f1b
commit b4f6dcc474
8 changed files with 302 additions and 230 deletions

View file

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
0.10.7.1856 RC 3
0.10.8.1863 RC 4

View file

@ -634,6 +634,19 @@ function env($key)
{
return getenv($key);
}
if ($key == 'DOCUMENT_ROOT')
{
$offset = 0;
if (!strpos(env('SCRIPT_NAME'), '.php'))
{
$offset = 4;
}
return substr(env('SCRIPT_FILENAME'), 0, strlen(env('SCRIPT_FILENAME')) - (strlen(env('SCRIPT_NAME')) + $offset));
}
if ($key == 'PHP_SELF')
{
return r(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
}
return null;
}

View file

@ -387,6 +387,40 @@ class Controller extends Object
return $this->_viewClass->render($action, $layout, $file);
}
/**
* Gets the referring URL of this request
*
* @param string $default Default URL to use if HTTP_REFERER cannot be read from headers
* @param boolean $local If true, restrict referring URLs to local server
* @access public
*/
function referer($default = null, $local = false)
{
$ref = env('HTTP_REFERER');
$base = FULL_BASE_URL . $this->webroot;
if ($ref != null && defined(FULL_BASE_URL))
{
if (strpos(env('HTTP_REFERER'), $base) == 0)
{
return substr($ref, strlen($base) - 1);
}
elseif (!$local)
{
return $ref;
}
}
if ($default != null)
{
return $default;
}
else
{
return '/';
}
}
/**
* Sets data for this view. Will set title if the key "title" is in given $data array.
*

View file

@ -152,7 +152,11 @@ class AjaxHelper extends Helper
$href = $title;
}
$options['url'] = $href;
if (!isset($options['url']))
{
$options['url'] = $href;
}
if (isset($confirm))
{
$options['confirm'] = $confirm;
@ -414,15 +418,15 @@ class AjaxHelper extends Helper
if(!isset($options['class']))
{
$options['class'] = "auto_complete";
$options['class'] = "auto_complete";
}
$divOptions = array('id' => $options['id'] . "_autoComplete", 'class' => $options['class']);
return $this->Html->input($field, $htmlOptions) .
$this->Html->tag("div", $divOptions, true) . "</div>" .
$this->Javascript->codeBlock("new Ajax.Autocompleter('" . $options['id'] . "', '" .
$divOptions['id'] . "', '" . $this->Html->url($url) . "'" . $this->__optionsForAjax($ajaxOptions) . ");");
$this->Html->tag("div", $divOptions, true) . "</div>" .
$this->Javascript->codeBlock("new Ajax.Autocompleter('" . $options['id'] . "', '" .
$divOptions['id'] . "', '" . $this->Html->url($url) . "'" . $this->__optionsForAjax($options) . ");");
}
/**

View file

@ -26,8 +26,8 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
$modelName = Inflector::singularize($this->name);
$modelKey = $modelName;
$modelName = Inflector::singularize($this->name);
$modelKey = $modelName;
?>
<h1><?php echo $type.' '.Inflector::humanize($modelName);?></h1>
@ -41,30 +41,26 @@ else
{
echo $html->formTag('/'. Inflector::underscore($this->name).'/create');
}
echo $form->generateFields( $fieldNames );
echo $form->generateSubmitDiv( 'Save' )
echo $form->generateFields( $fieldNames );
echo $form->generateSubmitDiv( 'Save' )
?>
</form>
<ul class='actions'>
<?php
if($type == 'Edit')
{
echo "<li>".$html->link('Delete '.Inflector::humanize($modelName), '/'.$this->viewPath.'/destroy/'.$data[$modelKey][$this->controller->{$modelName}->primaryKey])."</li>";
echo "<li>".$html->link('Delete '.Inflector::humanize($modelName), '/'.$this->viewPath.'/destroy/'.$data[$modelKey][$this->controller->{$modelName}->primaryKey])."</li>";
}
echo "<li>".$html->link('List '.Inflector::humanize($modelName), '/'.$this->viewPath.'/index')."</li>";
if($type == 'Edit')
{
foreach($fieldNames as $field => $value)
{
if(isset($value['foreignKey']))
{
echo "<li>".$html->link( "View ".Inflector::humanize($value['controller']), "/".Inflector::underscore($value['controller'])."/show/".$data[$modelKey][$field] )."</li>";
}
}
}
echo "<li>".$html->link('List '.Inflector::humanize($modelName), '/'.$this->viewPath.'/index')."</li>";
if($type == 'Edit')
{
foreach( $fieldNames as $field => $value )
{
if( isset( $value['foreignKey'] ) )
{
echo "<li>".$html->link( "View ".Inflector::humanize($value['controller']), "/".Inflector::underscore($value['controller'])."/show/".$data[$modelKey][$field] )."</li>";
}
}
}
?>
</ul>

View file

@ -29,67 +29,86 @@
<h1>List <?php echo Inflector::humanize($this->name)?></h1>
<?php
$model = Inflector::singularize($this->name);
$modelKey = $model;
$humanName = Inflector::humanize($this->name);
$humanSingularName = Inflector::singularize( $humanName );
// var_dump( $data );
$model = Inflector::singularize($this->name);
$modelKey = $model;
$humanName = Inflector::humanize($this->name);
$humanSingularName = Inflector::singularize( $humanName );
if(!empty($this->controller->{$model}->alias))
{
foreach ($this->controller->{$model}->alias as $key => $value)
{
$alias[] = $key;
}
}
?>
<table class="inav" cellspacing="0">
<tr>
<?php foreach ( $fieldNames as $fieldName ) { ?>
<th><?php echo $fieldName['prompt'];?></th>
<?php } ?>
<th>Actions</th>
</tr>
<?php
$iRowIndex = 0;
<?php
foreach ($fieldNames as $fieldName)
{
?>
<th><?php echo $fieldName['prompt'];?></th>
<?php
}
?>
<th>Actions</th>
</tr>
<?php
$iRowIndex = 0;
if(is_array($data))
{
foreach ($data as $row)
{
if($iRowIndex++ % 2 == 0)
{
echo "<tr>";
}
else
{
echo "<tr class='altRow'>";
}
if( is_array( $data ) )
{
foreach ( $data as $row ) {
if( $iRowIndex++ % 2 == 0 )
$count = 0;
foreach($fieldNames as $field=>$value)
{
?>
<td>
<?php
if(isset($value['foreignKey']))
{
echo "<tr>";
} else {
echo "<tr class='altRow'>";
$otherModelKey = Inflector::underscore($value['modelKey']);
$otherControllerName = $value['controller'];
$otherModelObject =& ClassRegistry::getObject( $otherModelKey );
if(is_object($otherModelObject))
{
$displayText = $row[$alias[$count]][ $otherModelObject->getDisplayField() ];
}
else
{
$displayText = $row[$alias[$count]][$field];
}
echo $html->link( $displayText, "/".Inflector::underscore($otherControllerName)."/show/".$row[$modelKey][$field] );
$count++;
}
foreach( $fieldNames as $field=>$value ) { ?>
<td>
<?php
if( isset($value['foreignKey']) )
{
// this is a foreign key, figure out what the display field should be for this model.
$otherModelKey = Inflector::underscore($value['modelKey']);
$otherControllerName = $value['controller'];
$otherModelObject =& ClassRegistry::getObject( $otherModelKey );
$alias = array_search($value['table'],$this->controller->{$model}->alias);
if( is_object($otherModelObject) )
{
$displayText = $row[$alias][ $otherModelObject->getDisplayField() ];
} else{
$displayText = $row[$alias][$field];
}
echo $html->link( $displayText, "/".Inflector::underscore($otherControllerName)."/show/".$row[$modelKey][$field] );
} else {
echo $row[$modelKey][$field];
} ?>
</td>
<?php } // end for each $fieldNames as $field=>value ?>
<td class="listactions"><?php echo $html->link('View',"/".$this->viewPath."/show/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
<?php echo $html->link('Edit',"/".$this->viewPath."/edit/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
<?php echo $html->link('Delete',"/".$this->viewPath."/destroy/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
</td>
</tr>
<?php } // end for each data as row
} // end if( $data )?>
else
{
echo $row[$modelKey][$field];
}
?>
</td>
<?php
}
?>
<td class="listactions"><?php echo $html->link('View',"/".$this->viewPath."/show/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
<?php echo $html->link('Edit',"/".$this->viewPath."/edit/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
<?php echo $html->link('Delete',"/".$this->viewPath."/destroy/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
</td>
</tr>
<?php
}
}
?>
</table>
<ul class="actions">
<li><?php echo $html->link('New '.$humanSingularName, '/'.$this->viewPath.'/add'); ?></li>
</ul>
</ul>

View file

@ -7,10 +7,10 @@
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright (c) 2006, Cake Software Foundation, Inc.
* Copyright (c) 2006, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
@ -29,16 +29,13 @@
<h1>New <?php echo Inflector::humanize($this->name)?></h1>
<?php
echo $html->formTag('/'. Inflector::underscore($this->name).'/create');
echo $form->generateFields( $fieldNames );
echo $form->generateSubmitDiv( 'Add' )
echo $html->formTag('/'. Inflector::underscore($this->name).'/create');
echo $form->generateFields( $fieldNames );
echo $form->generateSubmitDiv( 'Add' )
?>
</form>
<ul class='actions'>
<?php
echo "<li>".$html->link('List '.Inflector::humanize($this->name), '/'.$this->viewPath.'/index')."</li>";
echo "<li>".$html->link('List '.Inflector::humanize($this->name), '/'.$this->viewPath.'/index')."</li>";
?>
</ul>

View file

@ -28,175 +28,184 @@
?>
<?php
$modelName = Inflector::singularize($this->name);
$modelKey = Inflector::underscore($modelName);
$objModel =& ClassRegistry::getObject($modelKey);
$modelName = Inflector::singularize($this->name);
$modelKey = Inflector::underscore($modelName);
$objModel =& ClassRegistry::getObject($modelKey);
if(!empty($objModel->alias))
{
foreach ($objModel->alias as $key => $value)
{
$alias[] = $key;
}
$count = 0;
}
?>
<h1>Show <?php echo Inflector::humanize($modelName)?></h1>
<h1>Show
<?php echo Inflector::humanize($modelName)?>
</h1>
<dl>
<?php foreach($fieldNames as $field => $value)
{
echo "<dt>".$value['prompt']."</dt>";
if(isset($value['foreignKey']))
{
$alias = array_search($value['table'],$objModel->alias);
$otherModelObject =& ClassRegistry::getObject(Inflector::underscore($objModel->tableToModel[$value['table']]));
$displayField = $otherModelObject->getDisplayField();
$displayText = $data[$alias][$displayField];
<?php
foreach($fieldNames as $field => $value)
{
echo "<dt>".$value['prompt']."</dt>";
if(isset($value['foreignKey']))
{
$otherModelObject =& ClassRegistry::getObject(Inflector::underscore($objModel->tableToModel[$value['table']]));
$displayField = $otherModelObject->getDisplayField();
$displayText = $data[$alias[$count]][$displayField];
if(!empty($data[$objModel->tableToModel[$objModel->table]][$field]) && (isset($displayText)))
{
echo "<dd>".$html->link($displayText, '/'.Inflector::underscore($value['controller']).'/show/'
.$data[$objModel->tableToModel[$objModel->table]][$field] )."</dd>";
}
else
{
echo "<dd>&nbsp;</dd>";
}
}
else
{
// this is just a plain old field.
if( !empty($data[$objModel->tableToModel[$objModel->table]][$field]))
{
echo "<dd>".$data[$objModel->tableToModel[$objModel->table]][$field]."</dd>";
}
else
{
echo "<dd>&nbsp;</dd>";
}
}
}
if(!empty($data[$objModel->tableToModel[$objModel->table]][$field]) && (isset($displayText)))
{
echo "<dd>".$html->link($displayText, '/'.Inflector::underscore($value['controller']).'/show/'
.$data[$objModel->tableToModel[$objModel->table]][$field] )."</dd>";
}
else
{
echo "<dd>&nbsp;</dd>";
}
$count++;
}
else
{
if( !empty($data[$objModel->tableToModel[$objModel->table]][$field]))
{
echo "<dd>".$data[$objModel->tableToModel[$objModel->table]][$field]."</dd>";
}
else
{
echo "<dd>&nbsp;</dd>";
}
}
}
?>
</dl>
<ul class='actions'>
<?php
echo "<li>".$html->link('Edit '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/edit/'.$data[$objModel->tableToModel[$objModel->table]][$this->controller->{$modelName}->primaryKey])."</li>";
echo "<li>".$html->link('Delete '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/destroy/'.$data[$objModel->tableToModel[$objModel->table]][$this->controller->{$modelName}->primaryKey])."</li>";
echo "<li>".$html->link('List '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/index')."</li>";
echo "<li>".$html->link('New '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/add')."</li>";
echo "<li>".$html->link('Edit '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/edit/'.$data[$objModel->tableToModel[$objModel->table]][$this->controller->{$modelName}->primaryKey])."</li>";
echo "<li>".$html->link('Delete '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/destroy/'.$data[$objModel->tableToModel[$objModel->table]][$this->controller->{$modelName}->primaryKey])."</li>";
echo "<li>".$html->link('List '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/index')."</li>";
echo "<li>".$html->link('New '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/add')."</li>";
foreach( $fieldNames as $field => $value )
{
if( isset( $value['foreignKey'] ) )
{
echo "<li>".$html->link( "List ".Inflector::humanize($value['controller']), "/".Inflector::underscore($value['controller'])."/index/")."</li>";
}
}
foreach( $fieldNames as $field => $value )
{
if( isset( $value['foreignKey'] ) )
{
echo "<li>".$html->link( "List ".Inflector::humanize($value['controller']), "/".Inflector::underscore($value['controller'])."/index/")."</li>";
}
}
?>
</ul>
<!--hasOne relationships -->
<?php
foreach ($objModel->hasOne as $association => $relation)
{
$model = $relation['className'];
$otherModelName = $objModel->tableToModel[$objModel->{$model}->table];
$controller = Inflector::pluralize($model);
$new = true;
echo "<div class='related'><H2>Related ".Inflector::humanize($association)."</H2>";
echo "<dl>";
if( isset($data[$association]) && is_array($data[$association]) )
{
foreach( $data[$association] as $field => $value )
{
if( isset($value) )
{
echo "<dt>".Inflector::humanize($field)."</dt>";
if( !empty($value) )
{
echo "<dd>".$value."</dd>";
}
else
{
echo "<dd>&nbsp;</dd>";
}
$new = null;
}
}
echo "</dl>";
if($new == null)
{
echo "<ul class='actions'><li>".$html->link('Edit '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/edit/{$data[$association][$objModel->{$model}->primaryKey]}")."</li></ul></div>";
}
else
{
echo "<ul class='actions'><li>".$html->link('New '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/add/{$data[$association][$objModel->{$model}->primaryKey]}")."</li></ul></div>";
}
}
}
foreach ($objModel->hasOne as $association => $relation)
{
$model = $relation['className'];
$otherModelName = $objModel->tableToModel[$objModel->{$model}->table];
$controller = Inflector::pluralize($model);
$new = true;
echo "<div class='related'><H2>Related ".Inflector::humanize($association)."</H2>";
echo "<dl>";
if(isset($data[$association]) && is_array($data[$association]))
{
foreach($data[$association] as $field => $value)
{
if(isset($value))
{
echo "<dt>".Inflector::humanize($field)."</dt>";
if(!empty($value))
{
echo "<dd>".$value."</dd>";
}
else
{
echo "<dd>&nbsp;</dd>";
}
$new = null;
}
}
echo "</dl>";
if($new == null)
{
echo "<ul class='actions'><li>".$html->link('Edit '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/edit/{$data[$association][$objModel->{$model}->primaryKey]}")."</li></ul></div>";
}
else
{
echo "<ul class='actions'><li>".$html->link('New '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/add/{$data[$association][$objModel->{$model}->primaryKey]}")."</li></ul></div>";
}
}
}
?>
<!-- HAS MANY AND HASANDBELONGSTOMANY -->
<?php
$relations = array_merge($objModel->hasMany, $objModel->hasAndBelongsToMany);
foreach($relations as $association => $relation)
{
$model = $relation['className'];
$count = 0;
$otherModelName = Inflector::singularize($model);
$controller = Inflector::pluralize($model);
$relations = array_merge($objModel->hasMany, $objModel->hasAndBelongsToMany);
foreach($relations as $association => $relation)
{
$model = $relation['className'];
$count = 0;
$otherModelName = Inflector::singularize($model);
$controller = Inflector::pluralize($model);
echo "<div class='related'><H2>Related ".Inflector::humanize(Inflector::pluralize($association))."</H2>";
if( isset($data[$association]) && is_array($data[$association]) )
{
echo "<div class='related'><H2>Related ".Inflector::humanize(Inflector::pluralize($association))."</H2>";
if(isset($data[$association]) && is_array($data[$association]))
{
?>
<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[$association][0] as $column=>$value ) {
<table class="inav" cellspacing="0">
<tr>
<?php
$bFound = false;
foreach($data[$association][0] as $column=>$value)
{
echo "<th>".Inflector::humanize($column)."</th>";
}
}
?>
<th>Actions</th>
</tr>
<th>Actions</th>
</tr>
<?php
// now find all matching rows
foreach( $data[$association] as $row )
foreach($data[$association] as $row)
{
echo "<tr>";
foreach($row as $column=>$value)
{
echo "<tr>";
foreach( $row as $column=>$value )
{
echo "<td>".$value."</td>";
}
?>
<?php if (isset($this->controller->{$modelName}->{$association}))
{?>
<td class="listactions"><?php echo $html->link('View',"/".Inflector::underscore($controller)."/show/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
<?php echo $html->link('Edit',"/".Inflector::underscore($controller)."/edit/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
<?php echo $html->link('Delete',"/".Inflector::underscore($controller)."/destroy/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
</td>
<?php
}
else
{?>
<td class="listactions"><?php echo $html->link('View',"/".Inflector::underscore($controller)."/show/{$row[$this->controller->{$modelName}->primaryKey]}/")?>
<?php echo $html->link('Edit',"/".Inflector::underscore($controller)."/edit/{$row[$this->controller->{$modelName}->primaryKey]}/")?>
<?php echo $html->link('Delete',"/".Inflector::underscore($controller)."/destroy/{$row[$this->controller->{$modelName}->primaryKey]}/")?>
</td>
<?php
}?>
<?php
echo "</tr>";
echo "<td>".$value."</td>";
}
}
if (isset($this->controller->{$modelName}->{$association}))
{
?>
</table>
<td class="listactions"><?php echo $html->link('View',"/".Inflector::underscore($controller).
"/show/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
<?php echo $html->link('Edit',"/".Inflector::underscore($controller).
"/edit/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
<?php echo $html->link('Delete',"/".Inflector::underscore($controller).
"/destroy/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
</td>
<?php
}
else
{
?>
<td class="listactions"><?php echo $html->link('View',"/".Inflector::underscore($controller).
"/show/{$row[$this->controller->{$modelName}->primaryKey]}/")?>
<?php echo $html->link('Edit',"/".Inflector::underscore($controller).
"/edit/{$row[$this->controller->{$modelName}->primaryKey]}/")?>
<?php echo $html->link('Delete',"/".Inflector::underscore($controller).
"/destroy/{$row[$this->controller->{$modelName}->primaryKey]}/")?>
</td>
<?php
}
echo "</tr>";
}
}
?>
</table>
<ul class="actions">
<?php
// add a link to create a new relation.
echo "<li>".$html->link('New '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/add/")."</li>";
echo "<li>".$html->link('New '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/add/")."</li>";
?>
</ul></div>
<?php } // end loop through relations
<?php
}
?>