一起学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、了解配置文件

 '我的应用',
    //默认布局
    '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
//打印结果:我的应用

你可能感兴趣的:(PHP)