如何解决设置未知属性:yii\log\Logger::targets
在我的系统中安装 Yii 后,当我尝试运行它时出现此错误。
未知属性 – yii\base\UnknownPropertyException 设置未知属性:yii\log\Logger::targets
解决方法
以下是我在 Yii 中实现日志记录时创建的一些文档,它可能对您有所帮助:
======================== 配置 xampp 以从本地主机代码发送电子邮件 ============== ==============================
C:\xampp\php\php.ini 文件的更改:
搜索【邮件功能】:
[mail function]
SMTP=localhost to SMTP=smtp.gmail.com
smtp_port=587
sendmail_from=me@example.com to sendmail_from=your email address
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header=Off
mail.log = syslog
C:\xampp\sendmail\sendmail.ini 的更改:
搜索[发送邮件]:
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=same as "sendmail_from" in php.ini file
auth_password=generated password for the email account
force_sender= same as "auth_username" in this file
================================================ = 重启 Xampp 服务器 ============================================== ========
================================================ ==== 在数据库中添加表 ========================================== ============== 如果存在“日志”,则删除表;
create table "log"
(
"id" number(20) NOT NULL PRIMARY KEY,"level" integer,"category" varchar(255),"log_time" number,"prefix" text,"message" text,key "idx_log_level" ("level"),key "idx_log_category" ("category")
);
============================================ 在 Yii2 中的配置项目 ================================================== /p>
-
在 app\config\console.php 和 app\config\web.php 这两个文件中添加“components”数组:
'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' => false,'transport' => [ 'class' => 'Swift_SmtpTransport','host' => 'smtp.gmail.com','username' => 'your email address (for testing on localhost use same as in ini files)','password' => 'generated password','port' => 587,'encryption' => 'tls',],//end of mailer 'log' => [ 'targets' => [ [ 'class' => 'yii\log\FileTarget','levels' => ['error','warning','info'],[ 'class' => 'yii\log\DbTarget',[ 'class' => 'yii\log\EmailTarget','mailer' => 'mailer',//'categories' => ['yii\db\*'],'message' => [ 'from' => ['your email address(for testing on localhost use same as in ini files)'],'to' => ['receiptent email address'],// end of targets 'flushInterval' => 1,//end of logs
//------------------------ web.php (日志配置设置) ------------- ------------//
//类别名称稍后会分配给消息:
Yii::info($message,'userNotification');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。