PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 19, 2022

[FIXED] delete button with confirmation in yii2

 March 19, 2022     crud, php, yii, yii2     No comments   

Issue

This view.php is generated with CRUD in Yii2 but the delete button doesn't confirm window.

But in index.php generated with CRUD in Yii2, The confirm window for delete worked.

<p>
    <?= Html::a('Edit', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
    <?= Html::a('Delete', ['delete', 'id' => $model->id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => 'Are you sure you want to delete this item?',
                'method' => 'post',
            ],
    ]) ?>
    <?= Html::a('Back','index', ['class' => 'btn btn-warning']) ?>
</p>

Delete Button in index.php:

<a href="var/delete?id=2" title="Delete" aria-label="Delete" data-pjax="0" data-confirm="Are you sure you want to delete this item?" data-method="post"><span class="glyphicon glyphicon-trash"></span></a>

Delete Button in view.php:

<a class="btn btn-danger" href="var/delete?id=2" data-confirm="Are you sure you want to delete this item?" data-method="post">Delete</a>

Solution

The section about yii.js is still in progress.

To get default support of confirmation you should register yii.js.

Using yii\web\YiiAsset

use yii\web\YiiAsset;
YiiAsset::register($this);

or registering script files (not recommend, just for example)

$this->registerJsFile('@yii/assets/yii.js', ['depends' => [\yii\web\JqueryAsset::className()]]);


Answered By - SiZE
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing