Giter Site home page Giter Site logo

belicfr / mvclite Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 1.56 MB

A lite PHP framework using MVC pattern.

License: MIT License

PHP 86.46% CSS 4.32% JavaScript 2.33% Hack 5.90% Sass 0.98%
ajax ajax-form ajax-request apache backend composer framework frontend html html-css html-css-javascript html5 javascript js nodejs php php8 server web website

mvclite's Introduction

About MVCLite

MVCLite is a lightweight MVC (Model-View-Controller) framework for building web applications in PHP. It provides a robust foundation for structuring your application's codebase, including features such as middlewares, routing system, ORM (Object-Relational Mapping), Twig templating engine integration, and more.

Features

  • Routing System: Define clean and intuitive URL routes to handle various HTTP requests.
  • Middlewares: Easily integrate pre-processing and post-processing logic into your application's request-response cycle.
  • ORM (Object-Relational Mapping): Simplify database interactions by mapping database tables to PHP objects.
  • Twig Integration: Use the Twig templating engine for separating logic from presentation in your views.
  • And More: MVCLite includes many other features to streamline your development process.

Installation

You can install MVCLite via Composer. Run the following command in your terminal:

composer create-project belicfr/mvclite

After installing MVCLite, you have to configure your application's settings in the config directory. The config.php file contains the main settings for your application.

const ROUTE_PATH_PREFIX = '/';

const DATABASE_CREDENTIALS = [

    "dbms"      =>  "mysql",

    "host"      =>  "localhost",
    "port"      =>  "3306",
    "charset"   =>  "utf8mb4",
    "name"      =>  "",
    "user"      =>  "",
    "password"  =>  ""

];

You also have to configure the htaccess file, you can use the .htaccess_example file as a base.

RewriteEngine On
RewriteBase /website/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !src/resources/(.*)$

RewriteRule ^(.*)$ index.php?route=$1 [QSA,L]

Usage

Router

Define your application's routes in the src/Router/routes.php file. Here's an example of a simple route:

Router::get('/path', Controller::class, "method");

You can also define routes with a custom name

Router::get('/path', Controller::class, "method")->setName('routeName');

ORM

The build-in ORM allows you to interact with your database. Here's an example of a simple SELECT query:

Model::select('column1', 'column2')
       ->where('column', 'value')
       ->orderBy('column', 'ASC')
       ->execute();

The is still in development and more features will be added in the future, if you want to do custom queries you can use the Database class.

Database::query('INSERT INTO table (column1, column2) VALUES (?, ?)', ['value1', 'value2']);

Middlewares

Middlewares are used to perform pre-processing logic on your application's request-response cycle. You can define a middleware in the constructor of your controller.

public function __construct()
{
    $this->middleware(AuthMiddleware::class);
}

Views

MVCLite uses the Twig templating engine for separating logic from presentation in your views. You can create your views in the src/Views directory and then render them in your controllers.

View::render('View', ['data' => $data]);

Twig

You can use the Twig templating engine to create your views. Here's an example of a simple Twig template:

<!DOCTYPE html>
<html>
<head>
    <title>{{ title }}</title>
</head>
<body>
{% if bool %}
    <h1>{{ content1 }}</h1>
{% else %}
    <p>{{ content2 }}</p>
{% endif %}
{{ include('Footer.twig', {'data': data}) }}
</body>
</html>

Contributing

Feel free to contribute to MVCLite by submitting a pull request, opening an issue, or sharing your ideas for new features.

License

MVCLite is open-sourced software licensed under the MIT license.

Credits

MVCLite is maintained by belicfr

Thank you to all the contributors who have helped make MVCLite better :

mvclite's People

Contributors

belicfr avatar quentinformatique avatar

Stargazers

Ayrton avatar  avatar François SP avatar

Watchers

 avatar

mvclite's Issues

few key features are missing

I tried to used your project with twig, but it's missing a some keys features:

  • a component management with twig. It could be a nice addition
  • a better documentation
  • finish the ORM

error in readme

In the readme file, you have :

View::render('view.twig', ['data' => $data]);

It should be :

View::render('view, ['data' => $data]);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.