updating scaffold links and views

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5107 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-05-15 05:38:56 +00:00
parent b77a0af14a
commit 3a9799c554
4 changed files with 34 additions and 35 deletions

View file

@ -175,20 +175,27 @@ class Scaffold extends Object {
$this->scaffoldTitle = Inflector::humanize($this->viewPath);
$this->scaffoldActions = $controller->scaffold;
$this->controller->pageTitle= __('Scaffold :: ', true) . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle;
$path = '/';
$this->controller->set('path', $path);
$this->controller->set('controllerName', $this->name);
$this->controller->set('controllerAction', $this->action);
$this->controller->set('modelClass', $this->modelClass);
$this->controller->set('modelKey', $this->modelKey);
$this->controller->set('viewPath', $this->viewPath);
$this->controller->set('humanSingularName', Inflector::humanize($this->modelKey));
$this->controller->set('humanPluralName', Inflector::humanize($this->viewPath));
$alias = array();
if(!empty($this->ScaffoldModel->alias)) {
$alias = array_combine(array_keys($this->ScaffoldModel->alias), array_keys($this->ScaffoldModel->alias));
}
$this->controller->set('alias', $alias);
$linked = array();
foreach($this->ScaffoldModel->tableToModel as $model){
if($model !== $this->modelClass) {
$linked[$model] = Inflector::tableize($model);
}
}
$this->controller->set('linked', $linked);
$this->controller->set('primaryKey', $this->ScaffoldModel->primaryKey);
$this->controller->set('displayField', $this->ScaffoldModel->getDisplayfield());
$this->__scaffold($params);
@ -213,6 +220,8 @@ class Scaffold extends Object {
return $this->controller->flash(sprintf(__("No id set for %s::view()", true), Inflector::humanize($this->modelKey)),
'/' . Inflector::underscore($this->controller->viewPath));
}
$this->controller->set('hasOne', $this->ScaffoldModel->hasOne);
$this->controller->set('relations', $relations = array_merge($this->ScaffoldModel->hasMany, $this->ScaffoldModel->hasAndBelongsToMany));
$this->controller->data = $this->ScaffoldModel->read();
$this->controller->set('data', $this->controller->data);
$this->controller->set('fieldNames', $this->controller->generateFieldNames($this->controller->data, false));

View file

@ -45,11 +45,8 @@ echo $form->end(__('Save', true)); ?>
echo "<li>".$html->link($humanPluralName, array('action' => 'index'))."</li>";
foreach($alias as $nav) {
if(!strpos($nav, $modelClass)) {
$navKey = Inflector::pluralize(Inflector::underscore($nav));
echo '<li>'.$html->link(Inflector::humanize($navKey), array('controller'=> $navKey)).'</li>';
}
foreach($linked as $name => $controller) {
echo '<li>'.$html->link(Inflector::humanize($controller), array('controller'=> $controller)).'</li>';
}
?>
</ul>

View file

@ -25,9 +25,6 @@
*/
?>
<h2><?php echo $humanPluralName;?></h2>
<?php
$modelObj =& ClassRegistry::getObject($modelKey);
?>
<p><?php
echo $paginator->counter(array(
'format' => 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%'
@ -69,7 +66,7 @@ if(is_array($data)) {
} else {
$displayText = $row[$alias[$value['model']]][$field];
}
echo $html->link($displayText, $path . $otherControllerPath . "/view/".$row[$modelClass][$field]);
echo $html->link($displayText, array('controller'=> $otherControllerPath, 'action'=>'view', $row[$modelClass][$field]));
} else {
echo $row[$modelClass][$field];
}
@ -77,7 +74,7 @@ if(is_array($data)) {
</td>
<?php } ?>
<td class="actions">
<?php $id = $row[$modelClass][$modelObj->primaryKey]; ?>
<?php $id = $row[$modelClass][$primaryKey]; ?>
<?php echo $html->link(__('View', true), array('action' => 'view', $id)) ?>
<?php echo $html->link(__('Edit', true), array('action' => 'edit', $id)) ?>
<?php echo $html->link(__('Delete', true), array('action' => 'delete', $id), null, sprintf(__("Are you sure you want to delete id %s?", true), $id)) ?>
@ -98,13 +95,9 @@ if(is_array($data)) {
<?php
echo '<li>'.$html->link(__('New ', true).$humanSingularName, array('action' => 'add')).'</li>';
foreach($alias as $nav) {
if(!strpos($nav, $modelClass)) {
$navKey = Inflector::pluralize(Inflector::underscore($nav));
echo '<li>'.$html->link(Inflector::humanize($navKey), array('controller'=> $navKey)).'</li>';
}
foreach($linked as $name => $controller) {
echo '<li>'.$html->link(Inflector::humanize($controller), array('controller'=> $controller)).'</li>';
}
?>
</ul>
</div>

View file

@ -24,9 +24,6 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
?>
<?php
$modelObj =& ClassRegistry::getObject($modelKey);
?>
<h2><?php echo sprintf(__("View %s", true), $humanSingularName)?></h2>
<dl>
<?php
@ -45,8 +42,12 @@ foreach($fieldNames as $field => $value) {
$othereDisplayField = $otherModelObj->getDisplayField();
$displayText = $data[$alias[$value['model']]][$othereDisplayField];
if(!empty($data[$modelClass][$field]) && (!empty($displayText))) {
echo "<dd {$class}>".$html->link($displayText, $path . $otherControllerPath.'/view/'
.$data[$modelClass][$field] )."</dd>";
echo "<dd {$class}>"
.$html->link($displayText,
array('controller'=> $otherControllerPath, 'action'=>'view',
$data[$modelClass][$field])
)
."</dd>";
} else {
echo "<dd {$class}>&nbsp;</dd>";
}
@ -62,8 +63,8 @@ foreach($fieldNames as $field => $value) {
<div class="nav">
<ul>
<?php
echo '<li>' . $html->link(sprintf(__("Edit %s", true), $humanSingularName), array('action' => 'edit', $data[$modelClass][$modelObj->primaryKey])) . '</li>';
echo '<li>' . $html->link(sprintf(__("Delete %s", true), $humanSingularName), array('action' => 'delete', $data[$modelClass][$modelObj->primaryKey]), null, sprintf(__("Are you sure you want to delete id %s?", true), $data[$modelClass][$modelObj->primaryKey])) . '</li>';
echo '<li>' . $html->link(sprintf(__("Edit %s", true), $humanSingularName), array('action' => 'edit', $data[$modelClass][$primaryKey])) . '</li>';
echo '<li>' . $html->link(sprintf(__("Delete %s", true), $humanSingularName), array('action' => 'delete', $data[$modelClass][$primaryKey]), null, sprintf(__("Are you sure you want to delete id %s?", true), $data[$modelClass][$primaryKey])) . '</li>';
echo '<li>' . $html->link(sprintf(__("List %s", true), $humanPluralName), array('action' => 'index')) . '</li>';
echo '<li>' . $html->link(sprintf(__("New %s", true), $humanSingularName), array('action' => 'add')) . '</li>';
@ -78,7 +79,7 @@ foreach($fieldNames as $field => $value) {
<!--hasOne relationships -->
<?php
$j = 0;
foreach ($modelObj->hasOne as $associationName => $relation) {
foreach ($hasOne as $associationName => $relation) {
$otherModelKey = Inflector::underscore($relation['className']);
$otherModelObj =& ClassRegistry::getObject($otherModelKey);
$otherControllerPath = Inflector::pluralize($otherModelKey);
@ -120,7 +121,6 @@ echo "</div>";
<!--hasMany and hasAndBelongsToMany relationships -->
<?php
$relations = array_merge($modelObj->hasMany, $modelObj->hasAndBelongsToMany);
foreach($relations as $associationName => $relation) {
$otherModelKey = Inflector::underscore($relation['className']);