tp5.1相关

这里只是个人记录用的~~~

1.生成项目
composer create-project topthink/think=5.1.* tp5(tp5为文件夹名 也就是项目名)

2.生成模块
php think build --module admin

3.生成控制器
php think make:controller admin/Index --plain

4.生成模型
php think make:model admin/User

5.生成验证器
php think make:validate admin/User

6.nginx修改内容部分
  location / {
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
            }
        try_files $uri $uri/ /index.php$is_args$args;
        autoindex on;
    }

7.邮件扩展
http://packagist.org
搜phpmailer
安装命令:composer require phpmailer/phpmailer直接在项目目录下面执行
配置写在了application目录下的common.php这个公共文件中
方法如下:
<?php
// 应用公共文件

// 发送邮件
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

function mailto($to, $title, $content)
{
    $mail = new PHPMailer(true);

    try {
        //Server settings
        $mail->SMTPDebug = 0;                      // 启用详细调试输出
        $mail->isSMTP();                                            // 使用SMTP发送
        $mail->Host       = 'smtp.163.com';                    // 设置要通过的SMTP服务器
        $mail->SMTPAuth   = true;                                   // 启用SMTP身份验证
        $mail->Username   = '[email protected]';                     // SMTP用户名
        $mail->Password   = 'zc4hero';                               // SMTP密码
        $mail->SMTPSecure = 'ssl';         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
        $mail->Port       = 465;                                    // 要连接到的TCP端口
        $mail->CharSet    = 'utf-8';
        //Recipients
        $mail->setFrom('[email protected]', '一颗糊涂淡');
        $mail->addAddress($to);     // 添加收件人

        // Content
        $mail->isHTML(true);                                  // 设置邮件格式到HTML
        $mail->Subject = $title;                  // 邮件主题
        $mail->Body    = $content;                      // 邮件内容

        return $mail->send();
    } catch (Exception $e) {
        exception($mail->ErrorInfo, 1001);                     //tp5内置的抛出异常的方法
    }
}
// 发送邮件部分结束
直接在需要发送的地方调用mailto()方法

8.验证码安装
composer require topthink/think-captcha=2.0.*
使用:
在模版内添加验证码的显示代码

<div>{:captcha_img()}</div>

或者

<div><img src="{:captcha_src()}" alt="captcha" /></div>
验证:
然后使用框架的内置验证功能(具体可以参考验证章节),添加captcha验证规则即可

$this->validate($data,[
    'captcha|验证码'=>'require|captcha'
]);

如果没有使用内置验证功能,则可以调研内置的函数手动验证

if(!captcha_check($captcha)){
 // 验证失败
};

猜你喜欢

转载自www.cnblogs.com/zhangcheng001/p/12298629.html