yii2不渲染以查看只是刷新页面

发布于 2025-02-10 04:59:35 字数 405 浏览 2 评论 0原文

view.php代码零件:

<a href="/goods/viewgood/<?=$good['GoodGallery'][0]['id']?>" class="btn btn-primary">View Picture</a>

viewgood.php

<?php
echo 'hello';

goodscontroller.php

 public function viewgood($id = null) {
       
 
   }

单击按钮查看图片图片我的页面只是刷新而不是转到viewgood.php 我在做什么错误? 我是yii2中的早点

view.php code part:

<a href="/goods/viewgood/<?=$good['GoodGallery'][0]['id']?>" class="btn btn-primary">View Picture</a>

viewgood.php

<?php
echo 'hello';

GoodsController.php

 public function viewgood($id = null) {
       
 
   }

After clicking on button View Picture my page just refreshing instead of going to viewgood.php
What am I doing incorrectly?
I am a begginer in Yii2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

才能让你更想念 2025-02-17 04:59:35

尝试

<a href="index.php?r=goods/viewgood/<?=$good['GoodGallery'][0]['id']?>" class="btn btn-primary">View Picture</a>

在锚定标签html中使用您的需求,请使用完整的路线,以便使用快捷方式尝试使用

<?= Html::a('View Picture', ['/goods/viewgood/', 'id' => $good['GoodGallery'][0]['id']], ['class' => 'btn btn-primary']) ?>

Try use

<a href="index.php?r=goods/viewgood/<?=$good['GoodGallery'][0]['id']?>" class="btn btn-primary">View Picture</a>

in a anchor tag html your need use the complete route, for use shortcut you try use

<?= Html::a('View Picture', ['/goods/viewgood/', 'id' => $good['GoodGallery'][0]['id']], ['class' => 'btn btn-primary']) ?>
黑色毁心梦 2025-02-17 04:59:35

view.php

您可以使用html:a(),或者在示例中使用url助手到()函数为锚定标签生成适当的路由。

<a href="<?=Url::to(['/goods/viewgood', 'id' => $good['GoodGallery'][0]['id']] ); ?>" class="btn btn-primary">View Picture</a>

goodscontroller.php

public function actionViewgood($id=null){
  //fetch the data e.g.
  $model = Good::findOne(id); 

 //Do some extra code checking when no record is found like throw an exception or set a flash error message, etc.

 //render the viewgood and pass the data (if needed)
  return $this->render('viewgood', [
        'model' => $model
    ]);
}

viewgood.php

<?php
    //do what you want with the data passed by the controller. E.g. print the name of the good (if applicable)
    echo $model->name;

    //your other code ...
?>

view.php

You can use Html:a(), or in your example use Url helper to() function to generate the proper route for your anchor tag.

<a href="<?=Url::to(['/goods/viewgood', 'id' => $good['GoodGallery'][0]['id']] ); ?>" class="btn btn-primary">View Picture</a>

GoodsController.php

public function actionViewgood($id=null){
  //fetch the data e.g.
  $model = Good::findOne(id); 

 //Do some extra code checking when no record is found like throw an exception or set a flash error message, etc.

 //render the viewgood and pass the data (if needed)
  return $this->render('viewgood', [
        'model' => $model
    ]);
}

viewgood.php

<?php
    //do what you want with the data passed by the controller. E.g. print the name of the good (if applicable)
    echo $model->name;

    //your other code ...
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文