JSMF
better plain text emails
使用此框架,您可以构建一个基于基于MVC的PHP应用程序(模型视图对照器)应用程序,也可以将其用作有用的PHP类的集合。框架的所有部分都可以单独使用。
有关所有可用类和方法,请参见APIIndex。
在此不完整状态时,请参考示例申请。
您可以通过作曲家安装JSMF。将以下依赖性添加到您的composer.json
{
"require" : {
"janst123/jsmf" : " >=1.0.0 "
}您也可以从此存储库中克隆JSMF(使用版本标签或克隆主分支以进行最新更改)。在这种情况下,您必须编写自己的自动加载器。
仅当您要将整个应用程序基于JSMF上时才需要。您也可以使用JSMF自动加载器或您自己的单个类使用单一类。
将此代码放在您的应用程序索引文件中。通过此文件路由所有请求(有关如何使用此最小设置将所有请求路由到index.php的介绍)请参阅此GIST)。
如果不存在一个或多个URL零件,则该应用程序将始终使用“索引”操作(“索引”控制器,“索引”模块)。
示例:请求http://主机将尝试调用模块“ index” - > indexController-> indexaction,请求http:// http:// host/misc/faq会调用模块为“ misc” - > faqcontroller-> indexaction
<?php
define ( ' DEV_SERVER ' , true ); // define this
define ( ' SRC ' , realpath ( dirname ( __FILE__ ) . ' /../ ' ));
require ( SRC . ' /vendor/autoload.php ' );
try {
// optional: load an application wide config
JSMF Config:: load ( SRC . ' /config/base.config.php ' );
// optional: load application wide translations
JSMF Language:: loadTranslations ( SRC . ' /language/translations ' , ' de ' );
// optional: route special URLs to special modules / controllers / actions ( I always place the legal texts in a Module named misc)
JSMF Request:: addRoute ( ' /^/disclaimer/?$/i ' , ' misc ' , ' index ' , ' disclaimer ' ); // route a request to /disclaimer to the disclaimer Action in the IndexController in the module "misc"
JSMF Request:: addRoute ( ' /^/privacy/?$/i ' , ' misc ' , ' index ' , ' privacy ' );
// register the autoloader and run the application
JSMF Application:: registerAutoloader ();
JSMF Application:: run ();
// output the applications response (can be HTML, JSON ...)
JSMF Response:: output ();
} catch ( JSMF Exception NotFound $ e ) {
// do some special things for not-found errors e.g. redirect to a static 404 page
JSMF Request:: redirect ( ' /404.html ' );
JSMF Response:: output (); // output method also sends the headers (here: the Location header)
} catch ( JSMF Exception $ e ) {
// output is done by JSMF
JSMF Response:: setException ( $ e );
JSMF Response:: output ();
} catch ( Exception $ e ) {
// do something on common non-JSMF Exception
}