use yii\helpers\Html;
public static $aliases = ['@yii' => __DIR__];
namespace app\components;
class View extends yii\web\View {
public $bodyId;
/* Yii allows you to add magic getter methods by prefacing method names with "get" */
public function getBodyIdAttribute() {
return ($this->bodyId != '') ? 'id="' . $this->bodyId . '"' : '';
}
}
<body <?=$this->BodyIdAttribute?>>
return [
// ...
'components' => [
// ...
'view' => [
'class' => 'app\components\View'
]
]
];
return [
'components' => [
'mail' => [
'useFileTransport' => true,
],
'urlManager' => [
'showScriptName' => true,
],
'db' => [
'dsn' => 'mysql:host=localhost;dbname=mysqldb_test',
],
],
];
$I->amOnPage('register');
$I->fillField('username', 'testuser');
$I->fillField('password', 'qwerty');
$I->click('Register');
$I->seeRecord('app\models\User', array('name' => 'testuser'));
return [
'components' => [
'request' => [
'enableCsrfValidation' => false,
]
];
use yii\filters\AccessControl;
class DefaultController extends Controller {
// ...
public function behaviors() {
return [
// ...
'class' => AccessControl::className(),
'only' => ['create', 'login', 'view'],
'rules' => [
[
'allow' => true,
'actions' => ['login', 'view'],
'roles' => ['?']
],
[
'allow' => true,
'actions' => ['create'],
'roles' => ['@']
]
]
];
}
// ...
}
if (YII_ENV_DEV) {
// ...
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '::1']
]
}
yii migrate/create create_user_table
<?php
use yii\db\Schema;
class m140924_153425_create_user_table extends \yii\db\Migration
{
public function up()
{
}
public function down()
{
echo "m140924_153425_create_user_table cannot be reverted.\n";
return false;
}
}
public function up()
{
$this->createTable('user', [
'id' => Schema::TYPE_PK,
'username' => Schema::TYPE_STRING . ' NOT NULL',
'password_hash' => Schema:: TYPE_STRING . ' NOT NULL'
], null);
}
public function down()
{
$this->dropTable('user');
}
./yii migrate
./yii migrate/down
return [
// ...
'components' => [
// ...
'db' => [
// ...
'enableSchemaCache' => true,
'schemaCacheDuration' => 3600,
'schemaCache' => 'cache',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
];
./yii asset/template config.php
<?php
return [
'jsCompressor' => 'java -jar compiler.jar --js {from} --js_output_file {to}',
'cssCompressor' => 'java -jar yuicompressor.jar --type css {from} -o {to}',
'bundles' => [
// 'yii\web\YiiAsset',
// 'yii\web\JqueryAsset',
],
'targets' => [
'app\config\AllAsset' => [
'basePath' => 'path/to/web',
'baseUrl' => '',
'js' => 'js/all-{hash}.js',
'css' => 'css/all-{hash}.css',
],
],
'assetManager' => [
'basePath' => __DIR__,
'baseUrl' => '',
],
];
yii asset config.php /app/assets_compressed.php
'components' => [
// ...
'assetManager' => [
'bundles' => require '/app/assets_compressed.php'
]
]
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有