PHPackages                             ravikisha/nexaphp - 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. [Framework](/categories/framework)
4. /
5. ravikisha/nexaphp

ActiveLibrary[Framework](/categories/framework)

ravikisha/nexaphp
=================

NexaPHP is a lightweight and flexible MVC (Model-View-Controller) framework for PHP, designed to streamline the development of web applications. With NexaPHP, you can quickly build scalable and maintainable PHP applications by separating concerns and promoting code organization.

20PHP

Since Nov 5Pushed 1y ago2 watchersCompare

[ Source](https://github.com/Ravikisha/NexaPHP)[ Packagist](https://packagist.org/packages/ravikisha/nexaphp)[ RSS](/packages/ravikisha-nexaphp/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![NexaPHP](https://camo.githubusercontent.com/792a3d998ee023691a5c6361e8dd3033dfc3e0d88e06f1ddfe6a9abebd3709cf/68747470733a2f2f726176696b697368612e6769746875622e696f2f6173736574732f6e6578617068702e706e67)](https://camo.githubusercontent.com/792a3d998ee023691a5c6361e8dd3033dfc3e0d88e06f1ddfe6a9abebd3709cf/68747470733a2f2f726176696b697368612e6769746875622e696f2f6173736574732f6e6578617068702e706e67)

NexaPHP
=======

[](#nexaphp)

 [![PHP Version](https://camo.githubusercontent.com/ce0c70c519047d0e507604f03e6e8ae6c27bcc072027e899680d9bf93804dc76/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d626c7565)](https://camo.githubusercontent.com/ce0c70c519047d0e507604f03e6e8ae6c27bcc072027e899680d9bf93804dc76/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d626c7565) [![Version](https://camo.githubusercontent.com/1aae4bbb2f78ca33effee230a4e2667b68bb4beed10b9ecf6060c3999b063099/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56657273696f6e2d312e302e302d677265656e)](https://camo.githubusercontent.com/1aae4bbb2f78ca33effee230a4e2667b68bb4beed10b9ecf6060c3999b063099/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56657273696f6e2d312e302e302d677265656e) [![License](https://camo.githubusercontent.com/8174925d009b42074d50ab5cc7e29fcb1aa613b0d9cb2e43097697a40cf90fa4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f77)](https://camo.githubusercontent.com/8174925d009b42074d50ab5cc7e29fcb1aa613b0d9cb2e43097697a40cf90fa4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f77) [![Status](https://camo.githubusercontent.com/68f57094243f26ff940c08332313b6c4c798c89dd44ebb77360207881baad096/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5374617475732d446576656c6f706d656e742d726564)](https://camo.githubusercontent.com/68f57094243f26ff940c08332313b6c4c798c89dd44ebb77360207881baad096/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5374617475732d446576656c6f706d656e742d726564)

**NexaPHP** is a PHP MVC framework designed to provide a lightweight and flexible structure for building web applications. This document provides a detailed guide to understanding and utilizing the framework.

Table of Contents
-----------------

[](#table-of-contents)

- [NexaPHP](#nexaphp)
    - [Table of Contents](#table-of-contents)
        - [1. Installation](#1-installation)
        - [2. Setup](#2-setup)
        - [3. Core Components](#3-core-components)
        - [4. Controllers](#4-controllers)
        - [5. Routing](#5-routing)
        - [6. Database Integration](#6-database-integration)
        - [7. Middleware](#7-middleware)
        - [8. Views](#8-views)
        - [9. Forms and Fields](#9-forms-and-fields)
        - [10. Session Management](#10-session-management)
        - [11. Exception Handling](#11-exception-handling)
        - [12. User Authentication](#12-user-authentication)
        - [13. Events](#13-events)
        - [14. Sample Application](#14-sample-application)
    - [License](#license)
    - [Open Source](#open-source)

---

### 1. Installation

[](#1-installation)

Install NexaPHP via Composer:

```
composer require ravikisha/nexaphp
```

---

### 2. Setup

[](#2-setup)

To start, initialize the **Application** class with the root directory and configuration:

```
use ravikisha\nexaphp\Application;

$config = [
    'userClass' => \app\models\User::class,
    'db' => [
        'dsn' => 'mysql:host=localhost;dbname=testdb',
        'user' => 'root',
        'password' => 'password'
    ]
];

$app = new Application(__DIR__, $config);
```

- `userClass`: Defines the User model.
- `db`: Database configuration parameters (`dsn`, `user`, `password`).

---

### 3. Core Components

[](#3-core-components)

The NexaPHP framework includes several core components:

- **Application**: The main entry point to the application.
- **Router**: Manages route handling.
- **Request**: Handles HTTP requests.
- **Response**: Sends HTTP responses.
- **Database**: Manages database interactions.
- **Session**: Manages session data.

[![NexaPHP Architecture](https://camo.githubusercontent.com/773714a5e60d2a05a45f95c93e84743c5e23e1311922d7c5594f86c686313d45/68747470733a2f2f726176696b697368612e6769746875622e696f2f6173736574732f6e6578617068706469616772616d2e706e67)](https://camo.githubusercontent.com/773714a5e60d2a05a45f95c93e84743c5e23e1311922d7c5594f86c686313d45/68747470733a2f2f726176696b697368612e6769746875622e696f2f6173736574732f6e6578617068706469616772616d2e706e67)

---

### 4. Controllers

[](#4-controllers)

Controllers in NexaPHP define how to handle different routes.

```
namespace app\controllers;

use ravikisha\nexaphp\Controller;

class SiteController extends Controller
{
    public function home()
    {
        return $this->render('home');
    }

    public function contact()
    {
        return $this->render('contact');
    }
}
```

- **Controller::render()**: Renders a view.
- **setLayout()**: Sets a custom layout.

---

### 5. Routing

[](#5-routing)

Define routes using `Router::get()` for GET requests and `Router::post()` for POST requests:

```
$app->router->get('/', [SiteController::class, 'home']);
$app->router->post('/contact', [SiteController::class, 'contact']);
```

NexaPHP supports dynamic route parameters:

```
$app->router->get('/profile/{id}', [UserController::class, 'profile']);
```

- **Route parameters** can be accessed using `Request::getRouteParams()`.

---

### 6. Database Integration

[](#6-database-integration)

NexaPHP integrates with PDO for database management.

1. **Define a Model**:

    ```
    namespace app\models;

    use ravikisha\nexaphp\db\DBModel;

    class User extends DBModel
    {
        public string $id;
        public string $name;

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

        public function attributes(): array
        {
            return ['id', 'name'];
        }
    }
    ```
2. **Migrations**: Run migrations to manage the database structure.

    ```
    $app->db->applyMigrations();
    ```
3. **Querying**:

    - **save()**: Save a model instance.
    - **findOne()**: Retrieve a record by criteria.

---

### 7. Middleware

[](#7-middleware)

Middleware allows filtering and controlling request handling.

1. **Create Middleware**:

    ```
    namespace app\middlewares;

    use ravikisha\nexaphp\middlewares\BaseMiddleware;

    class AuthMiddleware extends BaseMiddleware
    {
        public function execute()
        {
            // Logic for authentication
        }
    }
    ```
2. **Apply Middleware**:

    ```
    $this->registerMiddleware(new AuthMiddleware(['profile', 'settings']));
    ```

---

### 8. Views

[](#8-views)

Views define how content is rendered. The **View** class handles view rendering.

```
// Render a view file located in views directory
return $this->render('viewName', ['param' => $value]);
```

1. **Layouts**:

    - Define layout files under `views/layouts`.
    - Use `{{content}}` to insert view content.
2. **Passing Parameters**:

    ```
    return $this->render('profile', ['name' => 'John Doe']);
    ```

---

### 9. Forms and Fields

[](#9-forms-and-fields)

Forms and fields are handled through classes in `ravikisha\nexaphp\form`.

1. **Form**:

    ```
    use ravikisha\nexaphp\form\Form;

    $form = Form::begin('/submit', 'post');
    echo $form->field($model, 'username');
    Form::end();
    ```
2. **Field Types**:

    ```
    echo (new Field($model, 'password'))->passwordField();
    ```

    Supported types: `password`, `email`, `number`, `date`, `file`, etc.

---

### 10. Session Management

[](#10-session-management)

The **Session** class provides functions for handling sessions.

- **setFlash()**: Set flash messages.
- **getFlash()**: Retrieve flash messages.
- **set()** and **get()**: Manage session data.

Example:

```
Application::$app->session->setFlash('success', 'Logged in successfully');
```

---

### 11. Exception Handling

[](#11-exception-handling)

The framework includes custom exceptions:

- **NotFoundException**: Triggered for invalid routes.
- **ForbiddenException**: Used for access control.

---

### 12. User Authentication

[](#12-user-authentication)

**UserModel** is an abstract class that provides basic functionality for user management.

```
class User extends UserModel
{
    public static function primaryKey(): string
    {
        return 'id';
    }

    public function getDisplayName(): string
    {
        return $this->username;
    }
}
```

- **login()**: Log in a user.
- **logout()**: Log out a user.
- **isGuest()**: Check if a user is logged in.

---

### 13. Events

[](#13-events)

The **Application** class supports custom events.

1. **Define an Event**:

    ```
    Application::$app->on(Application::EVENT_BEFORE_REQUEST, function () {
        // Before request logic
    });
    ```
2. **Trigger Events**:

    Use `triggerEvent()` to initiate custom behavior at various points in the application.

---

### 14. Sample Application

[](#14-sample-application)

Below is an example of setting up a simple application using NexaPHP:

```
// Load NexaPHP classes
require_once __DIR__ . '/vendor/autoload.php';

use ravikisha\nexaphp\Application;
use app\controllers\SiteController;

$config = [
    'userClass' => \app\models\User::class,
    'db' => [
        'dsn' => 'mysql:host=localhost;dbname=testdb',
        'user' => 'root',
        'password' => 'password'
    ]
];

// Initialize the application
$app = new Application(__DIR__, $config);

// Define routes
$app->router->get('/', [SiteController::class, 'home']);
$app->router->get('/contact', [SiteController::class, 'contact']);

// Run the application
$app->run();
```

---

> This Project in for the purpose of learning and understanding the MVC architecture and how it works. It is not intended to be used in production environments. For production, it is recommended to use a well-established framework like Laravel, Symfony, or Yii.

---

License
-------

[](#license)

This Project is licensed under the [MIT License](LICENSE).

Open Source
-----------

[](#open-source)

This Project is open source and contributions are welcome. Feel free to fork and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/dff645d037c993db386e1c92c91ccc84cf3000b93c15d1afdb9c4cebcd809079?d=identicon)[Ravikisha](/maintainers/Ravikisha)

---

Top Contributors

[![Ravikisha](https://avatars.githubusercontent.com/u/57055822?v=4)](https://github.com/Ravikisha "Ravikisha (43 commits)")

---

Tags

hacktoberfesthacktoberfest2024mvc-frameworkopen-sourcephp

### Embed Badge

![Health badge](/badges/ravikisha-nexaphp/health.svg)

```
[![Health](https://phpackages.com/badges/ravikisha-nexaphp/health.svg)](https://phpackages.com/packages/ravikisha-nexaphp)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M191](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M256](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M592](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
