canaryphp/canaryphpconservation

CanaryPHPConservation 简单的 PHP 保存管理

v1.0 2019-12-24 07:18 UTC

This package is auto-updated.

Last update: 2024-09-24 18:15:30 UTC


README

简单的 PHP 文件管理

类功能

  • 创建保存
  • 创建消息
  • 更新保存
  • 更新消息
  • 删除保存
  • 删除消息
  • 获取保存
  • 获取消息
  • 保存认证

如何安装

仅通过 Composer 可用

  • 命令
composer require canaryphp/canaryphpconservation
  • composer.json
{
    "require":{
        "canaryphp/canaryphpconservation"
    }
}
  • 安装后阅读: CanaryPHP START.mdSTART.md

示例

  1. 创建文件夹 templates
  • 下载 templates 文件夹并将其移动到您的项目目录: 下载
  1. 创建文件 index.php
<?php
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'index.php';
$c = "<a href=\"contacts.php\">Contacts</a>";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta content-type="text/html" charset="utf-8">
    <title>Chat with aida</title>
</head>
<body>
<center>
<?=$c?>
  1. 创建 contacts.php
<?php
require 'index.php';
$canary = new \CanaryPHPConservation\Canary();
$conservation = $canary->conservation('',new \CanaryPHPConservation\ConservationManager('conservations','messages'));
$res = $conservation->setViewer('3')->setReceiver('9')->setContactsTemplate(__DIR__.DS.'templates'.DS.'Contact.php');
$canary = new \CanaryPHPTools\Canary();
if ($canary->request()->is()->post){
    $res->registerConservation($_POST['title'],$_POST['sub']);
}
echo $res->getConservations();
?>
<form method="POST">
    <input type="text" placeholder="Conservation title"  name="title"><br>
    <input type="text" placeholder="Conservation subject"  value="" name="sub"><br>
    <input type="submit" value="Create"><br>
</form>
</center>
</body>
</html>
  1. 创建 msg.php
<?php
require 'index.php';
$canary = new \CanaryPHPConservation\Canary();
$id = $_GET['id'];
$conservation = $canary->conservation($id,new \CanaryPHPConservation\ConservationManager('conservations','messages'));
$res = $conservation->setViewer('3')->setReceiver('9')
                                ->setViewerTEXTMSGTemplate(__DIR__.DS.'templates'.DS.'ViewerTEXTMSG.php')
                                ->setViewerIMGMSGTemplate(__DIR__.DS.'templates'.DS.'ViewerIMGMSG.php')
                                ->setViewerVIDEOMSGTemplate(__DIR__.DS.'templates'.DS.'ViewerVIDMSG.php')
                                ->setViewerAUDIOMSGTemplate(__DIR__.DS.'templates'.DS.'ViewerAUDMSG.php')
                                ->setViewerATTACHMENTMSGTemplate(__DIR__.DS.'templates'.DS.'ViewerATTMSG.php')
                                ->setReceiverTEXTMSGTemplate(__DIR__.DS.'templates'.DS.'ReceiverTEXTMSG.php')
                                ->setReceiverIMGMSGTemplate(__DIR__.DS.'templates'.DS.'ReceiverIMGMSG.php')
                                ->setReceiverVIDEOMSGTemplate(__DIR__.DS.'templates'.DS.'ReceiverVIDMSG.php')
                                ->setReceiverAUDIOMSGTemplate(__DIR__.DS.'templates'.DS.'ReceiverAUDMSG.php')
                                ->setReceiverATTACHMENTMSGTemplate(__DIR__.DS.'templates'.DS.'ReceiverATTMSG.php')
                                ->setNoDATATemplate(__DIR__.DS.'templates'.DS.'NODATA.php')
                                ->setNoMSGTemplate(__DIR__.DS.'templates'.DS.'NOMSG.php');
if ($res->Auth()) {
$canary = new \CanaryPHPTools\Canary();
if ($canary->request()->is()->post){
    $res->registerMessage($_POST['msg'],$_POST['msg_type']);
}
$msgs = $res->getMessages();
}else{
    $msgs = "<center><h1>Authenfication Error</h1></center>";
}
?>
<?=$msgs?>
<form method="POST">
    <input type="text" name="msg"><br>
    <input type="text" value="1" name="msg_type"><br>
    <input type="submit" value="Send"><br>
</form>
</center>
</body>
</html>
  1. 访问 localhost/contacts.php
  • 输入保存的标题并点击创建
  • 点击保存
  • 编写消息并点击发送

注意

  • vendor 文件夹和 vendor/autoload.php 脚本由 composer 生成,不是 CanaryPHPFile 的部分