(Yii2)变量在发布后不起作用 [英] (Yii2) Variable not working from post
本文介绍了(Yii2)变量在发布后不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我简单的index.php文件
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
$this->title = 'Qwert';
?>
<?php $variable=1; //that variable
$f=ActiveForm::begin() ?>
<?php
if($variable==1){
echo Html::submitButton('First Button',['name'=>'b','value'=>1])."<br/>";
}else{
echo Html::submitButton('Second Button',['name'=>'b','value'=>2]);}
if(Yii::$app->request->post('b')==='1' ) {$variable=2;}
if(Yii::$app->request->post('b')==='2' ) {$variable=1;} ?>
<?php ActiveForm::end() ?>
因此,我想在单击 First 按钮后,它显示为 Second .我的错误在哪里?
So I want to after click First button it appears Second. Where is my mistake?
推荐答案
在我的 Controller 中,我必须添加返回值.
In my Controller, I have to add return.
if(Yii::$app->request->post('b')==='1' ) {$variable=2; return $this->render('index');}
if(Yii::$app->request->post('b')==='2' ) {$variable=1;return $this->render('index');}
这篇关于(Yii2)变量在发布后不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文