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
}