Skip to content

Commit

Permalink
Merge pull request #273 from schmunk42/feature/pivot-url-fix
Browse files Browse the repository at this point in the history
Fixed pivot url creating in crud view template
  • Loading branch information
schmunk42 committed Sep 8, 2020
2 parents 98e895c + 08f8b01 commit da489d0
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/generators/crud/default/views/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,24 @@
['class'=>'btn text-muted btn-xs']
) ?>\n";
// TODO: support multiple PKs
echo " <?= Html::a(

// pivot check
if ($relation->via !== null) {
$url = "['".$generator->createRelationRoute($relation, 'create')."']";
} else {
$url = "['".$generator->createRelationRoute($relation, 'create')."', '".
Inflector::id2camel($generator->generateRelationTo($relation),
'-',
true)."' => ['".key($relation->link)."' => \$model->".$model->primaryKey()[0]."]]";
}

echo " <?= Html::a(
'<span class=\"glyphicon glyphicon-plus\"></span> ' . ".$generator->generateString('New')." . ' ".
Inflector::singularize(Inflector::camel2words($name))."',
['".$generator->createRelationRoute($relation, 'create')."', '".
Inflector::id2camel($generator->generateRelationTo($relation),
'-',
true)."' => ['".key($relation->link)."' => \$model->".$model->primaryKey()[0]."]],
Inflector::singularize(Inflector::camel2words($name))."',
{$url},
['class'=>'btn btn-success btn-xs']
); ?>\n";

echo $addButton;

echo "</div>\n</div>\n"; #<div class='clearfix'></div>\n";
Expand Down

0 comments on commit da489d0

Please sign in to comment.