bomi/mvcat

PHP MVC library using configuration file

2.0.0 2022-09-28 21:00 UTC

This package is auto-updated.

Last update: 2024-05-29 05:27:10 UTC


README

GitHub issues GitHub release (latest by date)

MVC@PHP

library

Demo

  • see: DEMO
  • url: localhost/mvcat/demo

Composer

composer require bomi/mvcat

Using

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

  • see
  • change line to your base url
RewriteBase /mvcat/demo/

Configuration file

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"	
		}
	}
}

Call view in template

echo ${View::VIEW_RENDER};
  • use template
echo $this->view("users/form.inc", $params, "main");
  • render view without tepmplate
echo $this->view("users/form.inc", $params);

Controller

  • your controller should inherit the bomi\mvcat\base\Controller
  • example
  • fetch request information
$this->getRequestContext()->getMethod(); // POST, GET, PUT, DELETE, OPTIONS
$this->getRequestContext()->getPostData; // post data
$this->getRequestContext()->getGetData;  // get data

Languages

  1. define your languages in *.properties file. example
  2. add paths to manifest.json
  3. use in template or view:
  • Without arguments ${key}
  • With arguments ${key>>arg1,arg2,arg3}
  1. use in constructor
  • $this->_i18n->get("key", ["arg1, arg2"]);