thpglobal/thpclasses

dev-master 2022-01-25 16:26 UTC

This package is auto-updated.

Last update: 2022-09-25 17:55:41 UTC


README

由世界饥饿计划设计用于监控和评估数据的PHP类库,但对所有人公开,以便于快速建立数据库应用程序,特别适合在Google App Engine上使用。它的优势在于巧妙地使用$_SESSSION变量来使下拉筛选选择保持固定。

最近重构 - 2020年5月

除了传递查询结果($contents)之外,所有对$_SESSION的使用都已被$_COOKIE替代。这是为了消除过早的超时。这增加了复杂性,因为所有对$_COOKIE的更改都必须在Page::Start之前进行两次调用:$_COOKIE[$key]=$val和setcookie($key,val);

仅使用默认脚本运行

要创建最简单的GAE PHP 7.2应用程序,该应用程序将此包作为子模块使用,请创建以下文件夹和文件,这些文件将简单地运行内置页面系列以实现基本的数据库CRUD功能。

/includes/thpsecurity

// Any code that is special to your app, like connecting to a database or setting variables used throughout
$today=date("Y-m-d");
$user=$_SESSION["user"]; // set in the built in login scripts
if($user doesn't meet YOUR logical condition) Die("Not authorized, sorry"); 
$admin=if($user meets YOUR logical condition);
$can_edit=if($user meets YOUR logical condition for write permission);
$db = new PDO("mysql:unix_socket=/cloudsql/YOUR_PROJ:YOUR_REGION:YOUR_INSTANCE","YOUR_USER","YOUR_PWD")

/includes/menu.php

include("../thpclasses/includes/menu.php"); // copy the demo menu from the classes

/app.yaml

runtime: php73
entrypoint: thpclasses/app/index.php
handlers:

- url: /static
  static_dir: static

- url: /favicon.ico
  static_files: static/tst.png
  upload: static/tst.png

- url: .*
  script: auto
  secure: always

自动创建下拉菜单以链接到您的脚本

  • 将includes/menu.php更改为include("../thpclasses/includes/auto.php");
  • 创建类似于/app/apples /app/berries的文件夹
  • 创建类似于/app/apples/bartlet.php、/app/apples/green.php、/app/berries/blue.php、/app/berries/goose.php的脚本

部署后,您将拥有一个如下所示的运行中的应用程序