簡體   English   中英

獲取控制器yii2中的輸入數據?

[英]get input data in controller yii2?

我正在嘗試從yii2中的表單獲取輸入字段。 我需要在控制器中使用它,具體取決於值。 我試圖使用var_dump查看值,但它無法正常工作。 我得到“NULL”作為值..或者是否有辦法使表單使用不同的控制器。

調節器

 public function actionBlog()
 { 
     $thumbs= new Thumbs; 
     $thumbs->user=Yii::$app->user->identity->email;
     $thumbs->topic_id=Yii::$app->getRequest()->getQueryParam('id');
     $ra=Yii::$app->request->post('rate');
     var_dump($ra);
     if(ra=='down'){
         if ($thumbs->load(Yii::$app->request->post()) && $thumbs->validate()) {
             $thumbs->load($_POST);
             $thumbs->save();
             return $this->refresh();
         }
     } else {
         return $this->refresh();
     }
     return $this->render('blog',[
         'thumbs' => $thumbs,
     ]);
 }   

這是我的看法

  <?php $form = ActiveForm::begin(['id' => "contact-form"
        ]); 
  ?>
  <?= $form->field($thumbs, 'rate')?>
  <?= Html::submitButton('Update', ['blog'], ['class' => 'btn btn-primary']) ?>
  <?php ActiveForm::end(); ?>

我也厭倦了這樣做

$rr=Yii::$app->request->post($thumbs)['rate'];
var_dump( $rr);

我收到此錯誤:

isset或empty中的非法偏移類型

你在if(ra =='down')條件中有錯誤,'$'缺失。

如果我沒記錯的話,你應該試試

$ra=Yii::$app->request->post(['Thumbs']['rate']);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM