链接到html中的控制器操作

时间:2016-02-04 14:41:54

标签: php html yii2 action

可以创建

  

href =“控制器动作”

id为model?

我有这个代码,我想使用html href来控制器的动作。

<?php

use yii\helpers\Html;
use yii\helpers\Url;
?>  

<div class="news">
    <div class="context-menu">

        <a href="#" title="" id="dropdownProfile" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><i class="icon-circle-down"></i></a>
        <ul class="dropdown-menu" aria-labelledby="dropdownProfile">
            <li><a href="#" title="">Lorem ipsum</a></li>
            <li><a href="#" title="">Lorem ipsum</a></li>
        </ul>
    </div>
    <div class="header-news">
        <a href="#" title=""><img src="<?= Url::base(true) ?>/img/ania.jpg" alt=""></a>
        <p class="author"><?= $model->getUser($model->urUser_Id); ?></p>
        <p class="date"><?= $model->CreatedAt; ?></p>
    </div>
    <div class="content-news">
        <p><?= $model->Text; ?></p>
    </div>
    <?= $model->getStatus($model->cnNewsContentType_Id); ?> <br>

    <?php
    if ($model->getId($model->urUser_Id) == Yii::$app->user->identity->Id) {
        echo Html::a(Yii::t('app', 'Edytuj'), ['update', 'id' => $model->Id], ['class' => 'btn btn-primary']);
        echo Html::a(Yii::t('app', 'Usuń'), ['delete', 'id' => $model->Id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => Yii::t('app', 'Jesteś pewien, że chcesz usuńąć tego newsa?'),
                'method' => 'post',
            ],
        ]);
    }
    ?>
</div>

html中有下拉列表,我想粘贴控制器操作的链接。

<li><a href="#" title="">Lorem ipsum</a></li>
<li><a href="#" title="">Lorem ipsum</a></li>

而不是#我想使用此操作编辑并删除它可能吗?

1 个答案:

答案 0 :(得分:0)

try
{
    // 13.0.2000.0 is Crystal Reports for VS 2010
    // the first assembly is the most important one, but it also gets deployed by the project itself
    // because of this I picked two additional assemblies to check for
    var a = System.Reflection.Assembly.Load("CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral,PublicKeyToken=692fbea5521e1304");
    result = a != null;
    a = System.Reflection.Assembly.Load("CrystalDecisions.CrystalReports.TemplateEngine, Version=13.0.2000.0, Culture=neutral,PublicKeyToken=692fbea5521e1304");
    result &= a != null;
    a = System.Reflection.Assembly.Load("CrystalDecisions.Windows.Forms, Version=13.0.2000.0, Culture=neutral,PublicKeyToken=692fbea5521e1304");
    result &= a != null;
}
catch (FileNotFoundException ex)
{
    this.LogAction("Could not open the report. To view it, you need to have Crystal Reports v13.0.12 (32-bit only) installed.");
    result = false;
}
catch
{
    //Runtime is in GAC but something else prevents it from loading. (bad install?, etc)
    result = false;
}

或者你可以简单地为你的href指定一个网址

此示例用于相对路径

<li>
   <?php echo Html::a(Yii::t('app', 'yourItemLabel'), 
    Url::to(['/yourController/yourAction',
         'id' => $model->id]), ['class' => 'btn btn-primary']) ?>
</li>;