PHP开发实例大全(提高卷) 中文完整pdf扫描版[244MB]
views\site\vote.php:
controllers\SiteController.php:
<?php Pjax::begin(['enablePushState' => false]); ?> <?= Html::a('', ['site/upvote'], ['class' => 'btn btn-lg btn-warning glyphicon glyphicon-arrow-up']) ?> <?= Html::a('', ['site/downvote'], ['class' => 'btn btn-lg btn-primary glyphicon glyphicon-arrow-down']) ?> <h1><?= Yii::$app->session->get('votes', 0) ?></h1> <?php Pjax::end(); ?>
controllers\SiteController.php:
public function actionVote() { return $this->render('vote'); } public function actionUpvote() { $votes = Yii::$app->session->get('votes', 0); Yii::$app->session->set('votes', ++$votes); return $this->render('vote'); } public function actionDownvote() { $votes = Yii::$app->session->get('votes', 0); Yii::$app->session->set('votes', --$votes); return $this->render('vote'); }
转载请注明:谷谷点程序 » yii2 pajax简单实现投票效果