欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Yii2框架配置文件(Application屬性)與調(diào)試技巧實(shí)例分析

 更新時(shí)間:2019年05月27日 09:34:48   作者:學(xué)習(xí)筆記666  
這篇文章主要介紹了Yii2框架配置文件(Application屬性)與調(diào)試技巧,結(jié)合實(shí)例形式分析了Yii框架配置文件使用方法及記錄日志、調(diào)試等簡(jiǎn)單操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Yii2框架配置文件(Application屬性)與調(diào)試技巧。分享給大家供大家參考,具體如下:

配置文件

Yii2的主要配置文件config\web.php:

<?php
$params = require(__DIR__ . '/params.php');
$config = [
  'id' => 'basic',
  'basePath' => dirname(__DIR__),
  'bootstrap' => ['log'],
  'components' => [
    'request' => [
      // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
      'cookieValidationKey' => 'aldjaldjaldjaljd',
    ],
    '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' => require(__DIR__ . '/db.php'),
    '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',
  ];
  $config['bootstrap'][] = 'gii';
  $config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
  ];
}
return $config;

最后返回的一個(gè)數(shù)組,數(shù)組的key都是Application的屬性。

我們到控制器中來(lái)訪問(wèn)一下:

public function actionIndex()
{
    echo \Yii::$app->id,'<br>';
    echo \Yii::$app->name,'<br>';
    exit;
    return $this->render('index',['username'=>'張三','age'=>22]);
}

這里寫圖片描述

在入口文件web/index.php 里會(huì)加載這個(gè)config.php 配置文件,來(lái)創(chuàng)建一個(gè)Application

#...
$config = require(__DIR__ . '/../config/web.php');
(new yii\web\Application($config))->run();

調(diào)試技巧

助手類Yii,服務(wù)于整個(gè)框架,提供一些基礎(chǔ)方法:記錄日志、調(diào)試等
\Yii:warning()日志文件runtime/logs/app.log
\Yii::error()
\Yii::info()

\Yii:trace('調(diào)試內(nèi)容','test') 

這里寫圖片描述

這里寫圖片描述

更多關(guān)于Yii相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Yii框架入門及常用技巧總結(jié)》、《php優(yōu)秀開發(fā)框架總結(jié)》、《smarty模板入門基礎(chǔ)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論