1 |
namespace app\controllers; use yii\web\Controller; class SiteController extends Controller {public function actionSay($message = 'Hello') { return $this->render('say', ['message']); } } <?php use yii\helpers\Html; ?> <?= Html::encode($message) ?> |
2 |
<?php namespace app\models; use yii\base\Model; class EntryForm extends Model { public $name; public $email; public function rules() { return [ [['name', 'email'], 'required'], ['email', 'email'], ]; } } |
3 |
<?php namespace app\controllers; use Yii; use yii\web\Controller; use app\models\EntryForm; class SiteController extends Controller {public function actionEntry() { $model = new EntryForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) {return $this->render('entry-confirm', ['model' => $model]); } else {return $this->render('entry', ['model' => $model]); } } } |
4 |
<?php use yii\helpers\Html; ?> <p></p> <ul> <li><label>Name</label>: <?= Html::encode($model->name) ?></li> <li><label>Email</label>: <?= Html::encode($model->email) ?></li> </ul> |
5 |
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; ?> <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'name') ?> <?= $form->field($model, 'email') ?> <div class="form-group"> <?= Html::submitButton('send', ['class' => 'btn btn-primary']) ?> </div> <?php ActiveForm::end(); ?> |
6 |
<?php namespace app\assets; use yii\web\AssetBundle; class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ 'css/site.css', ]; public $js = [ ]; public $depends = [ 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', ]; } |
7 |
<?php namespace app\assets; use yii\web\AssetBundle; class FontAwesomeAsset extends AssetBundle { public $sourcePath = '@bower/font-awesome'; public $css = [ 'css/font-awesome.min.css', ]; public $publishOptions = [ 'only' => [ 'fonts/*', 'css/*', ] ]; } |
8 |
<?php namespace app\assets; use yii\web\AssetBundle; class FontAwesomeAsset extends AssetBundle { public $sourcePath = '@bower/font-awesome'; public $css = [ 'css/font-awesome.min.css', ]; public function init() { parent::init(); $this->publishOptions['beforeCopy'] = function ($from, $to) { if (basename(dirname($from)) !== 'font-awesome') { return true; } $dirname = basename($from); return $dirname === 'fonts' || $dirname === 'css'; }; } } |
Комментарии