Yii2 配置文件 常用配置总结

<?php 

// 主配置文件 

$config = array( 

    'modules' => array( 

        'gii' => array( 

            'class' => 'system.gii.GiiModule', 

            'password' => 'admin', 

        ), 

    ), 

    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..', 

    'name' => 'Yii学习', //项目名称 

    'preload' => array('log'), 

    'import' => array(//自动加载类 

        'application.models.*', 

        'application.components.*', 

    ), 

    'defaultController' => 'index', //默认控制器 

    'layout' => 'layout', //layout文件 

    'components' => array( 

        'db' => array(//数据库配置 

            'connectionString' => 'mysql:host=localhost;dbname=h.me', 

            'username' => 'root', 

            'password' => '', 

            'charset' => 'utf8', 

            'tablePrefix' => 'tp_', 

            'enableParamLogging' => true, //显示带参数的SQL 

        ), 

        'urlManager' => array( 

            'urlFormat' => 'path', //pathinfo模式 

            'showScriptName' => false, //隐藏index.php时需要设置false 

        //  'urlSuffix' => '.html', //url后缀相当于伪静态 

        ), 

        'errorHandler' => array( 

            'errorAction' => 'index/error', //404错误跳转到所在方法 

        ), 

        'log' => array(//日志 

            'class' => 'CLogRouter', 

            'routes' => array( 

                array( 

                    'class' => 'CWebLogRoute', 

                    'levels' => 'trace,error,waring', //Application Log 显示级别 

                    'categories' => 'system.*', //记录类别 

                ), 

            ), 

        ), 

    ), 

    'params' => require(dirname(__FILE__) . '/params.php'), 

); 

return $config; 

?>

==================== Advanced 版本的配置============================

<?php

return [

    'defaultRoute'=>'home/index',

    'components' => [

        'db' => [

            'class' => 'yii\db\Connection',

            'dsn' => 'mysql:host=localhost;dbname=dbname',

//            'dsn' => 'mysql:host=localhost;dbname=webshop',

            'username' => 'username',

            'password' => 'password',

            'charset' => 'utf8',

            'tablePrefix' => 'table_'

        ],

        'mailer' => [

            'class' => 'yii\swiftmailer\Mailer',

            'viewPath' => '@common/mail',

            // 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,

        ],

        'captcha' =>[

            'class' => 'yii\captcha\CaptchaAction',

            'minLength' => 4,

            'maxLength' => 4

        ],

//        'view' => [

//            'renderers' => [

//                    'html' => [

//                        'class' => 'yii\smarty\ViewRenderer',

//                        'options' => [

//                            'left_delimiter'  => '{{',

//                            'right_delimiter' => '}}'

//                        ]

//                ],

//            ],

//

//        ]

    ],

];
0

Yii config 配置的更多相关文章

  1. yii gii配置ip限制使用gii

    <?php $config = [ 'components' => [ 'request' => [ // !!! insert a secret key in the follow ...

  2. Web.config配置数据库连接

    web.config配置数据库连接   第一种:取连接字符串 string connString = System.Web.Configuration.WebConfigurationManager. ...

  3. Asp.net Web.Config - 配置元素 caching

    Asp.net Web.Config - 配置元素 caching 记得之前在写缓存DEMO的时候,好像配置过这个元素,好像这个元素还有点常用. 一.caching元素列表   元素 说明 cache ...

  4. asp.net中web.config配置节点大全详解

    最近网上找了一些关于Web.config配置节点的文章,发现很多都写的都比较零散,而且很少有说明各个配置节点的作用和用法.搜索了一下发现有一篇写的不错,这里引用一下 原文地址 http://www.c ...

  5. 十五天精通WCF——第二天 告别烦恼的config配置

    经常搞wcf的基友们肯定会知道,当你的应用程序有很多的“服务引用”的时候,是不是有一种疯狂的感觉...从一个环境迁移到另外一个环境,你需要改变的 endpoint会超级tmd的多,简直就是搞死了人.. ...

  6. web.config配置详细说明

    (一).Web.Config是以XML文件规范存储,配置文件分为以下格式 1.配置节处理程序声明    特点:位于配置文件的顶部,包含在<configSections>标志中. 2.特定应 ...

  7. EF连接MySQL数据Web.Config配置

    EF连接MySQL数据Web.Config配置 <?xml version="1.0" encoding="utf-8"?> <configu ...

  8. app.config 配置多项 配置集合 自定义配置(3)

    再说说利用app.config配置多个自定义的方法.先看这个例子:美国家庭Simpson的家里有父亲母亲和三个儿女,而中国的老王只有独生子女.结构如下: <?xml version=" ...

  9. springcloud之config配置中心-Finchley.SR2版

    本篇和大家分享的是springcloud-config配置中心搭建,写到这里突然想起自己曾今开源过基于Redis发布订阅编写的一个配置中心,刚看了git星数有点少哈哈,这里顺势发个连接欢迎大侠们点赞: ...

随机推荐

  1. Shell grep 和正则

    在grep中正则有三种模式, 分别是基础(-G), 扩展(-E)和Perl(-P)模式 basic 模式 不支持\d, 支持\w \s \b. ?, +, {, |, (, and ) 在basic ...

  2. 第二部分 职责型模式responsibility

    普通职责无法提供的内容,据此可以定义以下几种模式: 将职责集中到某个类的一个单独实例,单件模式 当一个对象发生改变时,依赖于这个对象的其他对象都能够得到通知,而这个发生改变的对象无须了解自己被其他哪些 ...

  3. php 关了浏览器也可以自动运行脚本

    <?php ignore_user_abort(); //即使Client断开(如关掉浏览器),PHP脚本也可以继续执行. set_time_limit(0); //执行时间为无限制,php默认 ...

  4. 转:应用JMeter测试solr请求

    使用JMeter测试solr请求 一.安装JMeter 在官网http://jmeter.apache.org/download_jmeter.cgi下载JMeter 直接解压JMeter安装包 Li ...

  5. android通过代码判断手机是否root

    只要/system/bin/su./system/xbin/su这两个文件中有一个存在,就表明已经具有ROOT权限,如果两个都不存在,则不具有ROOT权限. // 判断是否具有ROOT权限 publi ...

  6. webdriver入门

    webdriver是web自动化测试中的重要工具,通过webdriver可以灵活的操纵browser完成相关的测试,目前的webdriver对主流的浏览器均有支持, 如firefox ,chrome, ...

  7. applicationhost.config web.config

    在 IIS7 8两个版本中, 用户的配置,可以通过修改如上的配置文件来完成 applicationhost.config ,可以定义全局的 用户自己目录下的web.config,可以自己定义 但是,有 ...

  8. WebService测试方案

    1.WebService简介 WebService是一种革命性的分布式计算技术,本质上就是网络上可用的API,可以直接在网络环境调用的方法. WebService常用的框架有axis.xfire.cx ...

  9. gerrit push配置

    第一种方法: 在home目录下,编辑.gitconfig文件,添加 [remote "review"] url = ssh://someone@oneip:port/project ...

  10. Win7 Cygwin环境试验Nutch tutorial遇到的异常解决方法

    安装tutorial的步骤安装Nutch,当执行下面这条命令时出现异常 bin/nutch crawl urls - -topN Injector: starting at -- :: Injecto ...