我想将表单数据从我的视图发送到控制器,以将数据插入数据库.我已经创建了模型和控制器,但是当我将表单发送到带有操作的控制器时.它只刷新了数据未传递给控制器的页面,只会加载索引页面.这是我的表格:
['action' => '?r=twit/send-twit'] ]); ?> = $form->field($model,'twit')->textarea(); ?> = Html::SubmitButton('?????',['class' => 'btn btn-success green']); ?>
这是我的控制器动作,它在twitController
课堂上,不会被执行,数据不会传递到那里:
public function actionSendTwit() { $request = Yii::$app->request; $sag = $request->post('twit'); die(); if ($request->post('twit')){ $twitContent = $request->post('twit'); Twit::sendTwit($twitContent); \yii::$app->response->redirect('?r=twit/index',301)->send(); } }
Bloodhound.. 7
试试这样
$form = ActiveForm::begin([ 'action' => ['controller/action'], ]);
代替这个
$form = ActiveForm::begin([ 'options' => ['action' => '?r=twit/send-twit'] ]);
参考文档
试试这样
$form = ActiveForm::begin([ 'action' => ['controller/action'], ]);
代替这个
$form = ActiveForm::begin([ 'options' => ['action' => '?r=twit/send-twit'] ]);
参考文档