PHP Classes

Simple PHP Framework Application: Example MVC application with the Symfony framework

Recommend this page to a friend!
  Info   View files Example   View files View files (23)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-11-25 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 32 This week: 1All time: 10,930 This week: 108Up
Version License PHP version Categories
simple-php-framework 1.0The PHP License7Libraries, Design Patterns, PHP 7, Ap...
Description 

Author

This package provides an example MVC application with the Symfony framework.

It defines routes to process HTTP requests using controllers defined using class files.

Currently, it provides controller classes for:

- Check if the current year is a leap year

- Show a dashboard on the home page

- Search for Twitter posts

Picture of Nahidul Hasan
  Performance   Level  
Innovation award
Innovation award
Nominee: 7x

 

Example

<?php

define
('ROOT_DIR', realpath(__DIR__ . '/../'));

require_once
__DIR__.'/../vendor/autoload.php';

use
Symfony\Component\HttpFoundation\Request;
use
Symfony\Component\HttpFoundation\Response;
use
Symfony\Component\Routing;
use
Symfony\Component\HttpKernel;
use
Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use
Symfony\Component\HttpKernel\Controller\ControllerResolver;

function
render_template(Request $request)
{
   
extract($request->attributes->all(), EXTR_SKIP);
   
ob_start();
    include
sprintf(__DIR__.'/../src/pages/%s.php', $_route);

    return new
Response(ob_get_clean());
}


$dotenv = new Dotenv\Dotenv(ROOT_DIR);
$dotenv->load();

$request = Request::createFromGlobals();
$routes = include __DIR__.'/../src/routes.php';

$context = new Routing\RequestContext();
$matcher = new Routing\Matcher\UrlMatcher($routes, $context);

$controllerResolver = new ControllerResolver();
$argumentResolver = new ArgumentResolver();

$framework = new Simplex\Framework($matcher, $controllerResolver, $argumentResolver);
$response = $framework->handle($request);

$response->send();


Details

simple-php-framework

Trying to develop basic framework structure using symfony component

Installation:

Clone the repo

Run the following command

composer update

Run the PHP built-in server (php >= 7.0):

php -S 127.0.0.1:4321 -t web/ web/index.php

Now browse the project

http://127.0.0.1:4321/is_leap_year/2020

For docker

Run the following command

docker-compose up -d

Now browse the project

http://127.0.0.1:8097/is_leap_year/2020


  Files folder image Files  
File Role Description
Files folder imageConfig (1 file)
Files folder imagedocker (2 directories)
Files folder imagesrc (1 file, 6 directories)
Files folder imagetests (1 directory)
Files folder imageweb (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file docker-compose.yml Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file test.php Test Unit test class using PHPUnit

 Version Control Unique User Downloads Download Rankings  
 100%
Total:32
This week:1
All time:10,930
This week:108Up