PHPackages                             sigawa/mvc-core - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. sigawa/mvc-core

ActiveLibrary

sigawa/mvc-core
===============

Customized MVC mini-framework for development purposes with room for improvements.

v1.2.5(8mo ago)11722MITPHPCI failing

Since Mar 10Pushed 8mo agoCompare

[ Source](https://github.com/Jos254Kenya/k-mvc-core)[ Packagist](https://packagist.org/packages/sigawa/mvc-core)[ RSS](/packages/sigawa-mvc-core/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (31)Used By (0)

Custom MVC Framework
====================

[](#custom-mvc-framework)

[![PHP](https://camo.githubusercontent.com/f926042f81dd7d172a33225776fde37f8ed90988a5ef05037cf9950c5483df22/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e342d626c7565)](https://camo.githubusercontent.com/f926042f81dd7d172a33225776fde37f8ed90988a5ef05037cf9950c5483df22/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e342d626c7565)[![Composer](https://camo.githubusercontent.com/1c1fa61a75e206e34732ced9fc7517a703566a046824abb96b915dbd8987d12a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6d706f7365722d322e302d6f72616e6765)](https://camo.githubusercontent.com/1c1fa61a75e206e34732ced9fc7517a703566a046824abb96b915dbd8987d12a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6d706f7365722d322e302d6f72616e6765)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)

🚀 Introduction
--------------

[](#-introduction)

Welcome to the **Custom MVC Framework**! This framework is inspired by the routing capabilities of Laravel, Symfony, and CodeIgniter. It's designed to be **lightweight, flexible, and easy to use**, making it ideal for developers seeking to understand the inner workings of an MVC framework or build small to medium-sized applications without the overhead of a full-fledged framework. `

🛠️ Features
-----------

[](#️-features)

- **Lightweight and Fast**: Minimal overhead, optimized for performance.
- **MVC Structure**: Clean separation of concerns with Models, Views, and Controllers.
- **Powerful Routing**: Simplified and efficient routing system.
- **Database Integration**: User-friendly database abstraction layer.
- **CRUD Class**: Pre-built, customizable CRUD operations.
- **Command-Line Utility**: The `mcconsole` tool for seamless project management (create, make, serve, etc.).
- **Templating Engine**: Basic templating for dynamic views.
- **Error Handling**: Developer-friendly error pages and detailed stack traces.

📋 Requirements
--------------

[](#-requirements)

- PHP 7.4 or higher
- Composer

---

🧑‍💻 Installation
----------------

[](#‍-installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require sigawa/mvc-core:^1.0.6
```

### WHAT'S NEW

[](#whats-new)

API calls and protected routes using Middlewares Auth logic handling seamlessly with access\_tokens

### 2. Clone the Repository

[](#2-clone-the-repository)

```
git clone https://github.com/Jos254Kenya/k-mvc-core.git
```

After cloning, copy the `mcconsole` file to your project root directory to enable the command-line utility.

### 3. Initialize a New Project

[](#3-initialize-a-new-project)

```
php mcconsole create:project
```

Follow the prompts to set up your project structure automatically.

### 4. Configure Your Environment

[](#4-configure-your-environment)

Copy the example `.env` file and customize it for your environment:

```
cp .env.example .env
```

---

🚦 Getting Started
-----------------

[](#-getting-started)

### Running the Application

[](#running-the-application)

Use the built-in PHP server or the `mcconsole serve` command:

```
php -S localhost:8000 -t public
```

or

```
php mcconsole serve
```

Visit `http://localhost:8000` to view your application.

---

📚 Documentation
---------------

[](#-documentation)

### Routing

[](#routing)

Define routes in your `public/index.php` file:

```
$app->router->get('/', [NameController::class, 'index']);
$app->router->get('view/{id}', [NameController::class, 'view']);
$app->router->post('/submit', [NameController::class, 'functionName']);
$app->router->put('/submit/{id}', [NameController::class, 'functionName']);
$app->router->delete('/submit/{id}', [NameController::class, 'functionName']);
```

### Controllers

[](#controllers)

Generate a controller using:

```
php mcconsole make:controller ControllerName
```

Example:

```
namespace Hot360\v1\Controllers;

use sigawa\mvccore\Request;
use sigawa\mvccore\Response;
use sigawa\mvccore\Controller;

class HomeController extends Controller
{
    public function index(Request $request, Response $response)
    {
        $this->setLayout('main');
        return $this->render('home');
    }
}
```

### Models

[](#models)

Generate a model using:

```
php mcconsole make:model ModelName
```

Example:

```
namespace Hot360\v1\Models;

use sigawa\mvccore\db\DbModel;

class User extends DbModel
{
    public string $name = '';
    public string $email = '';

    public static function tableName(): string
    {
        return 'users';
    }

    public function attributes(): array
    {
        return ['name', 'email'];
    }

    public function rules(): array
    {
        return [
            'name' => [self::RULE_REQUIRED],
            'email' => [self::RULE_REQUIRED, self::RULE_EMAIL],
        ];
    }
}
```

### CRUD Operations

[](#crud-operations)

Example CRUD usage:

```
use sigawa\mvccore\db\CRUD;

$crud = new CRUD($databaseConnection);
$data = $crud->getAll('tableName', '*', []);
```

NOTE: More of these CRUD methods are implemented in the Model class and can be called statically in the model classes
=====================================================================================================================

[](#note-more-of-these-crud-methods-are-implemented-in-the-model-class-and-can-be-called-statically-in-the-model-classes)

Example:

```
