工作這是我簡單的index.php文件(Yii2)變量不能從後
<?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() ?>
所以我想點擊之後出現二首先按鈕。我的錯誤在哪裏?
php代碼被評估爲服務器端......所以在提交執行並且相關操作被調用後,post的內容可用..而這不是客戶端..如果您需要交互式服務器端你應該看看阿賈克斯 – scaisEdge