Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions assets/AppAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
* @license https://www.yiiframework.com/license/
*/

declare(strict_types=1);

namespace app\assets;

use yii\bootstrap5\BootstrapAsset;
use yii\web\AssetBundle;
use yii\web\View;
use yii\web\YiiAsset;

/**
* Main application asset bundle.
Expand All @@ -27,10 +32,10 @@ class AppAsset extends AssetBundle
'js/color-mode.js',
];
public $jsOptions = [
'position' => \yii\web\View::POS_HEAD,
'position' => View::POS_HEAD,
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap5\BootstrapAsset'
YiiAsset::class,
BootstrapAsset::class,
];
}
6 changes: 4 additions & 2 deletions commands/HelloController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* @license https://www.yiiframework.com/license/
*/

declare(strict_types=1);

namespace app\commands;

use yii\console\Controller;
Expand All @@ -26,9 +28,9 @@ class HelloController extends Controller
* @param string $message the message to be echoed.
* @return int Exit code
*/
public function actionIndex($message = 'hello world')
public function actionIndex(string $message = 'hello world'): int
{
echo $message . "\n";
echo "{$message}\n";

return ExitCode::OK;
}
Expand Down
8 changes: 4 additions & 4 deletions config/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
],
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
'class' => \yii\caching\FileCache::class,
],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'class' => \yii\log\FileTarget::class,
'levels' => ['error', 'warning'],
],
],
Expand All @@ -41,13 +41,13 @@
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'class' => \yii\gii\Module::class,
];
// configuration adjustments for 'dev' environment
// requires version `2.1.21` of yii2-debug module
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
'class' => \yii\debug\Module::class,
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
Expand Down
2 changes: 1 addition & 1 deletion config/db.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
'class' => 'yii\db\Connection',
'class' => \yii\db\Connection::class,
'dsn' => 'mysql:host=localhost;dbname=yii2basic',
'username' => 'root',
'password' => '',
Expand Down
10 changes: 6 additions & 4 deletions config/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
return [
'id' => 'basic-tests',
'basePath' => dirname(__DIR__),
'bootstrap' => [
\app\tests\Support\MailerBootstrap::class,
],
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
Expand All @@ -18,10 +21,9 @@
'db' => $db,
'mailer' => [
'class' => \yii\symfonymailer\Mailer::class,
'viewPath' => '@app/mail',
// send all mails to a file by default.
'messageClass' => \yii\symfonymailer\Message::class,
'useFileTransport' => true,
'messageClass' => 'yii\symfonymailer\Message'
'viewPath' => '@app/mail',
],
'assetManager' => [
'basePath' => __DIR__ . '/../web/assets',
Expand All @@ -30,7 +32,7 @@
'showScriptName' => true,
],
'user' => [
'identityClass' => 'app\models\User',
'identityClass' => \app\models\User::class,
],
'request' => [
'cookieValidationKey' => 'test',
Expand Down
27 changes: 16 additions & 11 deletions config/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'container' => [
'singletons' => [
\yii\mail\MailerInterface::class => [
'class' => \yii\symfonymailer\Mailer::class,
// send all mails to a file by default.
'useFileTransport' => true,
'viewPath' => '@app/mail',
],
],
],
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
Expand All @@ -17,26 +27,21 @@
'cookieValidationKey' => '',
],
'cache' => [
'class' => 'yii\caching\FileCache',
'class' => \yii\caching\FileCache::class,
],
'user' => [
'identityClass' => 'app\models\User',
'identityClass' => \app\models\User::class,
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => \yii\symfonymailer\Mailer::class,
'viewPath' => '@app/mail',
// send all mails to a file by default.
'useFileTransport' => true,
],
'mailer' => \yii\mail\MailerInterface::class,
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'class' => \yii\log\FileTarget::class,
'levels' => ['error', 'warning'],
],
],
Expand All @@ -58,14 +63,14 @@
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
'class' => \yii\debug\Module::class,
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];

$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'class' => \yii\gii\Module::class,
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
Expand Down
65 changes: 44 additions & 21 deletions controllers/SiteController.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
<?php

declare(strict_types=1);

namespace app\controllers;

use Yii;
use app\models\ContactForm;
use app\models\LoginForm;
use yii\captcha\CaptchaAction;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\base\Security;
use yii\mail\MailerInterface;
use yii\web\Controller;
use yii\web\ErrorAction;
use yii\web\Response;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;

class SiteController extends Controller
{
public function __construct(
$id,
$module,
private readonly MailerInterface $mailer,
private readonly Security $security,
$config = [],
) {
parent::__construct($id, $module, $config);
}

/**
* {@inheritdoc}
*/
public function behaviors()
public function behaviors(): array
{
return [
'access' => [
Expand All @@ -41,14 +57,14 @@ public function behaviors()
/**
* {@inheritdoc}
*/
public function actions()
public function actions(): array
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
'class' => ErrorAction::class,
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'class' => CaptchaAction::class,
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
'transparent' => true,
],
Expand All @@ -60,7 +76,7 @@ public function actions()
*
* @return string
*/
public function actionIndex()
public function actionIndex(): string
{
return $this->render('index');
}
Expand All @@ -70,29 +86,29 @@ public function actionIndex()
*
* @return Response|string
*/
public function actionLogin()
public function actionLogin(): Response|string
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}

$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$model = new LoginForm($this->security);

if ($model->load($this->request->post()) && $model->login()) {
return $this->goBack();
}

$model->password = '';
return $this->render('login', [
'model' => $model,
]);

return $this->render('login', ['model' => $model]);
}

/**
* Logout action.
*
* @return Response
*/
public function actionLogout()
public function actionLogout(): Response
{
Yii::$app->user->logout();

Expand All @@ -104,25 +120,32 @@ public function actionLogout()
*
* @return Response|string
*/
public function actionContact()
public function actionContact(): Response|string
{
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {

$contact = $model->load($this->request->post()) && $model->contact(
$this->mailer,
Yii::$app->params['adminEmail'],
Yii::$app->params['senderEmail'],
Yii::$app->params['senderName'],
);

if ($contact) {
Yii::$app->session->setFlash('contactFormSubmitted');

return $this->refresh();
}
return $this->render('contact', [
'model' => $model,
]);

return $this->render('contact', ['model' => $model]);
}

/**
* Displays about page.
*
* @return string
*/
public function actionAbout()
public function actionAbout(): string
{
return $this->render('about');
}
Expand Down
Binary file modified docs/images/about-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/about-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/contact-success-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/contact-success-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/error-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/error-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading