本文实例讲述了yii2框架配置文件(application属性)与调试技巧。分享给大家供大家参考,具体如下:
配置文件
yii2的主要配置文件config\web.php:
<?php$params = require(__dir__ . '/params.php');$config = [ 'id' => 'basic', 'bapath' => dirname(__dir__), 'bootstrap' => ['log'], 'components' => [ 复合制 'request' => [ // !!! inrt a cret key in the following (if it is empty) - this is required by cookie validation 'cookievalidationkey' => 'aldjaldjaldjaljd', ], 'cache' => [ 'class' => 'yii\caching\filecache', ], 'ur' => [ 'identityclass' => 'app\models\ur', 'enableautologin' => true, ], 不经意间的发现 '网络安全教育教案errorhandler' => [ 'erroraction' => 'site/error', ], 'mailer' => [ 风障 'class' => 'yii\swiftmailer\mailer', // nd all mails to a file by default. you have to t // 'ufiletransport' to fal and configure a transport // for the mailer to nd real emails. 'ufiletransport' => true, ], 'log' => [ 'tracelevel' => yii_debug ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\filetarget', 'levels' => ['error', 'warning'], ], ], ], 'db' =&g明星搭配t; require(__dir__ . '/db.php'), 'urlmanager' => [ 'enableprettyurl' => true, 'showscriptname' => fal, '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;
最后返回的一个数组,数组的key都是application的属性。
我们到控制器中来访问一下:
public function actionindex(){ echo \yii::$app->id,'<br>'; echo \yii::$app->name,'<br>'; exit; return $this->render('index',['urname'=>'张三','age'=>22]);}
在入口文件web/index.php 里会加载这个config.php 配置文件,来创建一个application
#...$config = require(__dir__ . '/../config/web.php');(new yii\web\application($config))->run();
调试技巧
助手类yii,服务于整个框架,提供一些基础方法:记录日志、调试等
\yii:warning()
日志文件runtime/logs/app.log
\yii::error()
\yii::info()
\yii:trace('调试内容','test')
更多关于yii相关内容感兴趣的读者可查看本站专题:《yii框架入门及常用技巧总结》、《php优秀开发框架总结》、《smarty模板入门基础教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于yii框架的php程序设计有所帮助。
本文发布于:2023-04-07 08:27:16,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/e4a7415d0d0dc4b54f7875cc116c8bfc.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Yii2框架配置文件(Application属性)与调试技巧实例分析.doc
本文 PDF 下载地址:Yii2框架配置文件(Application属性)与调试技巧实例分析.pdf
留言与评论(共有 0 条评论) |