bomi / mvcat
使用配置文件的PHP MVC库
2.0.0
2022-09-28 21:00 UTC
Requires
- php: >=8.1
- tebru/gson-php: ^0.7
README
MVC@PHP
库
演示
- 查看:DEMO
- URL: localhost/mvcat/demo
Composer
composer require bomi/mvcat
使用
use bomi\mvcat\service\Mvcat; require_once '../libs/vendor/autoload.php'; $language = "de"; // or your implementation to find a language Mvcat::build("manifest.json") ->language($language) ->execute(function(int $code, Exception $exception = null){ if ($code !== 200) { echo $exception->getMessage(); } });
.htaccess
- 查看
- 将行更改为您的基准URL
RewriteBase /mvcat/demo/
配置文件
Manifest.json
{ "globals" : { "baseurl" : "/mvcat/demo/", "asserts" : "public/asserts/" }, "routing" : { "views": "public/views/", "controllers": "bomi/mvcat/demo/classes/controllers/", "routes" : [ { "path": "/", "parameters": { "controller" : "home", "action": "index" } },{ "path": "users/{id:\\d+}", "methods" : ["GET"], "parameters": { "controller" : "User", "action": "user" } } ] }, "templates" : [ { "name" : "main", "path" : "public/templates/main.phtml" } ], "data" : { "connection" : { "host" : "", "dbname" : "", "username" : "", "password" : "", "additional" : { "key" : "value" } }, "repositories" : { "user" : "bomi/mvcat/demo/classes/repositories/UserRepository" } }, "i18n" : { "default" : "public/i18n/lang-de.properties", "languages" : { "ru" : "public/i18n/lang-ru.properties" } } }
在模板中调用视图
- 查看:main.phtml
echo ${View::VIEW_RENDER};
- 使用模板
echo $this->view("users/form.inc", $params, "main");
- 无模板渲染视图
echo $this->view("users/form.inc", $params);
控制器
- 您的控制器应继承bomi\mvcat\base\Controller
- 示例
- 获取请求信息
$this->getRequestContext()->getMethod(); // POST, GET, PUT, DELETE, OPTIONS $this->getRequestContext()->getPostData; // post data $this->getRequestContext()->getGetData; // get data
语言
- 在*.properties文件中定义您的语言。示例
- 将路径添加到manifest.json
- 在模板或视图中使用
- 无参数${key}
- 带参数${key>>>arg1,arg2,arg3}
- 在构造函数中使用
- $this->_i18n->get("key", ["arg1, arg2"]);