$('#contact-form').on('beforeSubmit', function (e) {
if (!confirm("Everything is correct. Submit?")) {
return false;
}
return true;
});
Yii::$app->response->format = Response::FORMAT_JSON;
public function actionMessage()
{
// Получение данных из модели, действия с данными
// ...
Yii::$app->response->format = Response::FORMAT_JSON;
return [
'status' => 'success',
'message' => $model
];
}
$this->view->params['customParam'] = 'customValue';
/* @var $this yii\web\View */
echo $this->params['customParam'];
renderAjax
:public function actionForm()
{
Yii::$app->response->format = Response::FORMAT_JSON;
// ...
return [
'status' => 'success',
'html' => $this->renderAjax('_form', [
// ...
])
];
}
localhost/web/site/login
?'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'contact' => 'site/contact',
'about' => 'site/about',
'login' => 'site/login',
],
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
rm public_html && ln -s application/web public_html
"codemix/yii2-localeurls": "*",
"zelenin/yii2-i18n-module": "dev-master",
"omgdef/yii2-multilingual-behavior": "~2.0"
'blog/<slug:[\w-_]+>' => 'blog/view',
<?= Url::to(['blog/view', 'slug' => $post->slug]) ?>
public function actionView($slug)
{
$post = Post::findBySlug($slug);
if($post === null) {
throw new NotFoundHttpException;
}
return $this->render('view', [
'post' => $post
]);
}