Skip to content
Open
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
2 changes: 1 addition & 1 deletion config/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
'request' => [
'cookieValidationKey' => 'test',
'enableCsrfValidation' => false,
'enableCsrfValidation' => true,
// but if you absolutely need it set cookie domain to localhost
/*
'csrfCookie' => [
Expand Down
2 changes: 0 additions & 2 deletions config/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@
],
],
'db' => require(__DIR__ . '/db.php'),
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
],
'params' => $params,
];
Expand Down
10 changes: 10 additions & 0 deletions controllers/AppController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace app\controllers;

use yii\web\Controller;

class AppController extends Controller
{

}
61 changes: 61 additions & 0 deletions controllers/ValidatorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace app\controllers;

use Yii;
use app\models\BooleanForm;
use app\models\TextForm;
use app\models\Captcha;
use app\models\OthersForm;

class ValidatorController extends AppController
{
/**
* @return string
*/
public function actionIndex()
{
$model = new TextForm();

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

/**
* @return string
*/
public function actionBoolean()
{
$model = new BooleanForm();

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

/**
* @return string
*/
public function actionCaptcha()
{
$model = new Captcha();

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

}

/**
* @return string
*/
public function actionOthers()
{
$model = new OthersForm;

return $this->render('others', [
'model' => $model
]);
}
}
21 changes: 21 additions & 0 deletions models/BooleanForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace app\models;

use yii\base\Model;

class BooleanForm extends Model
{
public $select;

/**
* @return array
*/
public function rules()
{
return [
['select', 'boolean', 'trueValue' => true, 'falseValue' => false, 'strict' => true],

];
}
}
17 changes: 17 additions & 0 deletions models/Captcha.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace app\models;

use yii\base\Model;

class Captcha extends Model
{
public $verifyCode;

public function rules()
{
return [
['verifyCode', 'captcha'],
];
}
}
30 changes: 30 additions & 0 deletions models/OthersForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace app\models;

use yii\base\Model;

class OthersForm extends Model
{
public $age; // validation compare
public $event_date; // validation date
public $default; // validation default
public $salary; // valid duble
public $integerCount; // valid int
public $email; // valid email
public $primaryImage; // valid img file

public function rules()
{
return [
['age', 'compare', 'compareValue' => 30, 'operator' => '>='],
[['event_date'], 'required'],
[['event_date'], 'date', 'format' => 'php:Y-m-d'],
['default', 'default', 'value' => null],
['salary', 'double'],
['integerCount', 'integer', 'min' => 0, 'max' => 5],
['email', 'email'],
['primaryImage', 'file', 'extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024],
];
}
}
23 changes: 23 additions & 0 deletions models/TextForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace app\models;

use Yii;
use yii\base\Model;

class TextForm extends Model
{
public $text;
public $name;

/**
* @return array
*/
public function rules()
{
return [
[['text'], 'required'],
['text', 'string', 'length' => [4, 24]],
];
}
}
16 changes: 16 additions & 0 deletions views/validator/boolean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>

<h1>Boolean validator</h1>

<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'select')->checkbox() ?>

<div class="form-group">
<?= Html::submitButton('Go', ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end() ?>
19 changes: 19 additions & 0 deletions views/validator/captcha.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\captcha\Captcha;
?>

<h1>Captcha validator</h1>

<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>

<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>

<?php ActiveForm::end() ?>
16 changes: 16 additions & 0 deletions views/validator/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>

<h1>Text validator</h1>

<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'text')->textInput(['autofocus' => true]) ?>

<div class="form-group">
<?= Html::submitButton('Go', ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end() ?>
81 changes: 81 additions & 0 deletions views/validator/others.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>

<h1>Others validator</h1>

<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'age') ?>

<div class="form-group">
<?= Html::submitButton('Go', ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end() ?>
<br>
<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'event_date')->textInput(); ?>

<div class="form-group">
<?= Html::submitButton('Go', ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end() ?>
<br>
<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'default')->textInput(); ?>

<div class="form-group">
<?= Html::submitButton('Go', ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end() ?>

<br>
<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'salary') ?>

<div class="form-group">
<?= Html::submitButton('Go', ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end() ?>

<br>
<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'integerCount') ?>

<div class="form-group">
<?= Html::submitButton('Go', ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end() ?>

<br>
<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'email') ?>

<div class="form-group">
<?= Html::submitButton('Go', ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end() ?>

<br>
<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'primaryImage')->fileInput() ?>

<div class="form-group">
<?= Html::submitButton('Go', ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end() ?>

11 changes: 11 additions & 0 deletions web/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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