一起学YII------基础框架

1、为什么叫YII
YII的缩写是Yes,it is
YII创始人薛强

2、YII特点
快速、安全、专业

3、YII官网
https://www.yiiframework.com/
yii分基础版、高级版;本笔记以基础版学习

4、YII目录介绍

basic/														应用根目录
	composer.json										    Composer配置文件,描述包信息
	config/													包含应用配置及其他配置
		console.php										    控制应用配置信息
		web.php												Web应用配置信息
	commands/												包含控制台命令类
	controllers/											包含控制器类
	models/													包含模型类
	runtime/												包含yii在运行时生成的文件
	vendor/													包含已经安装的Composer包,包含yii自身框架
	views/													包含视图文件
	web/													web应用根目录,包含web入口文件
		assets/												包含yii发布的资源文件
		index.php											应用入口
yii															yii控制台命令执行脚步

5、render(string,array,boolean)方法介绍

string							视图文件名,比如index.php,传入index即可
array							向视图传入的参数
boolean							是否渲染视图						

6、layout方法介绍

$this -> layout = true						使用视图
$this -> layout = false						不使用视图

7、了解配置文件

<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';

$config = [
    //应用名字,默认myApplication
    'name' => '我的应用',
    //默认布局
    'layout' => 'headerfooter',
    //应用ID,用于辨识应用唯一性
    'id' => 'basic',
    //应用跟目录
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'modules' => [
        'admin' => [
            'class' => 'app\modules\admin\Module',
        ],
    ],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'icez15011721135zhoub',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
        /*
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
        */
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // 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',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

return $config;

调用配置文件信息

    public function actionConfigInfo(){
        $this -> layout = false;
        //name 是we.php中的成员属性    可通过yii::$app调用web.php任何成员属性
        return \Yii::$app->name; 
    }
    
//网址输入:http://localhost/icez/web/index.html?r=message/config-info
//打印结果:我的应用
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值