<?php
$this->registerJs("
$('#create').click(function () {
$('project-form').attr('action', 'site/create_project');
$('project-form').submit();
});
$('#view').click(function () {
$('project-form').attr('action', 'site/view_project');
$('project-form').submit();
});
", View::POS_END);
?>
$('#project-form').attr('action', 'site/create_project');
<button class="button" data-action="<?= Url::to('site/create-project') ?>">Кнопа 1</button>
$('.button').click(function () {
$('form').attr('action', $(this).data('action'));
$('form').submit();
});
<?php
$this->registerJs("
$('.button').click(function () {
$('#project-form').attr('action', $(this).data('action'));
$('#project-form').submit();
});
", View::POS_READY);
?>
public function actionCreateProject()
{
$model = new Project();
$model->user_id_b = \Yii::$app->user->identity->getId();
if ($model->load(Yii::$app->request->post()) && $model->save())
{
\Yii::$app->getSession()->setFlash('success', \Yii::t('user', 'Проект добавлен'));
return $this->redirect(['project-profile', 'id' => $model->id]);
}
return $this->render('create-project', ['model' => $model]);
}