phpgram / mvc
A php mvc framework build on top of phpgram
1.5.3
2020-08-07 10:19 UTC
Requires
- php: ^7.1
- nyholm/psr7: 1.2.0
- nyholm/psr7-server: ^0.3.0
- phpgram/framework: ^2.1.0
- phpgram/framework-lib: ^0.6.1
- phpgram/mvc-lib: ^0.0.7
- phpgram/phpgram: ^1.8.0
- pimple/pimple: 3.2.3
README
phpgram mvc project
A fast and lightweight Mvc framework
Build on top of phpgram micro framework
Features
Simple and fast Http Routing
Psr 15 Middleware support
Dependency Injection with Psr 11 Container. Container from pimple
Php Template System
Basic Login, Authentication and Usermanagement via Php Session (or Psr 16 Cache)
Basic Psr 7 Cookies
Async Requests ready
Installation
via composer
composer create-project phpgram/mvc
Initialize / Set up
Local
copy file: env.local.php.dist and rename it to: env.local.php
complete the Database and Path information
- for ROOT_URL_PATH = the relative Url Path (e.g.:
hello.de/my_folder/
->/my_folder
is the path)
- for ROOT_URL_PATH = the relative Url Path (e.g.:
done :)
Deploy
Change the env.php to your deploy server
Documentation
Define Routes
<?php
//file /routes/web.routes.php
use Gram\Project\App\AppFactory as Route;
use App\Http\Controller\DummyController;
//With function as handler
// for Url: / its return: This page is the Start
Route::get("/",function (){
return "This page is the Start";
});
//with Controller (Class) as handler
//at Url: /controller: instantiate class DummyController (incl Dependency Injection) and call the method dummyFunction()
Route::get("/controller",DummyController::class."@dummyFunction");
//call this method with the value of id
Route::get("/user/{id}",DummyController::class."@dummyFunctionWithArgs");
Define Controller
<?php
//file: app/Http/Controller/DummyController.php
namespace App\Http\Controller;
use Gram\Mvc\Lib\Controller\BaseController;
class DummyController extends BaseController
{
private $tpl = 'index.temp'; //template without the .php!
public function dummyFunction()
{
return $this->view($this->tpl,[
'msg'=>"Test Controller"
]);
}
public function dummyFunctionWithArgs($id)
{
return $this->view($this->tpl,[
'userId'=>$id
]);
}
}
Define Templates
<?php
//file index.temp.php
$this->extend('defaultview'); //Values will being save for defaultview
$this->assign('h1',"Headline"); //assign variable h1 with the value Headline
//assign multiple variables at once
$this->assignArray([
'title'=>"Test page",
'my_awesome_button'=>"<button>Button</button>"
]);
?>
<?php
//Starts a section. The content will be buffered
$this->start();?>
<script type="text/javascript">
alert("Hello! I am an alert box!!");
</script>
<style></style>
<?php
//the content of this section will be available as variable head
$this->end('head');?>
<?php $this->start();?>
<h2>Test Template</h2>
<p>Welcome to phpgram mvc framework!</p>
<?php $this->end('content');?>
<?php
//file defaultview.php
?>
<html>
<head>
<?= $title?>
<?= $head?>
</head>
<body>
<h1><?= $h1?></h1>
<div class="content">
<p> <?= $content?> </p>
<?= $my_awesome_button?>
</div>
</body>
</html>
License
phpgram is open source and under MIT License