S
S
Soffeso2021-02-24 17:12:20
Yii
Soffeso, 2021-02-24 17:12:20

How to properly use Pjax for links?

Good day. There is a page where you need to accept applications from users or reject them.
view:

<?php foreach ($members as $member): ?>
    <?php if(($project->id == $member->project_id) && $member->status == 1): ?>
        <?php Pjax::begin(); ?>
                <?= $this->render('_waitmember', [
                    'project' => $project,
                    'member' => $member,
                ]) ?>
        <?php Pjax::end(); ?>
    <?php endif; ?>
<?php endforeach; ?>

_waitmember:
<li><?= $member->user->username; ?></li>
<a class="btn btn-success" 
    href="<?= Url::to(['projects/accept', 'id' => $member->user->id, 'project_id' => $project->id]) ?>"
    data-method="post" data-pjax="1">Принять
</a>
<a class="btn btn-danger" 
    href="<?= Url::to(['projects/reject', 'id' => $member->user->id, 'project_id' => $project->id]) ?>"
    data-method="post" data-pjax="1">Отклонить
</a>

controller:
public function actionAccept($id, $project_id)
    {
        $project = $this->findProject($project_id);
        $member = $project->isWaitingMember($id);

        if($member) {
            $member->status = 2;
            $member->save();
        }

        return $this->renderAjax('_waitmember', [
            'project' => $project,
            'member' => $member,
        ]);
    }

It looks like this:
60365ca7b72de497154333.png
The problem is that when you click on the "Accept" or "Reject" button, actions with the database occur as needed, but the block itself with the username and buttons remains.
Where could be the error or how can it be fixed?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question