ahmedali-dev/codenova
最新稳定版本:v0.0.4
Composer 安装命令:
composer create-project ahmedali-dev/codenova
包简介
php fremwork for handling route and request validation data and easy to use sql
README 文档
README
A lightweight PHP framework for building MVC-style web applications with simple routing, validation, and view handling.
✨ Features
-
🚦 Simple and expressive Routing (supports GET, POST, PUT, PATCH, DELETE)
-
✅ Built-in Validation
-
🖼️ View rendering with layout support
-
⚙️ Lightweight .env loader (pure PHP, no extra packages)
-
📦 Composer autoloading
-
🛠️ Lightweight and easy to extend
📥 Installation
Require the package via Composer:
composer require ahmedali-dev/codenova
Create a public/index.php file as your app entry point:
<?php require __DIR__ . "/../vendor/autoload.php"; // Initialize the view directory Core\Config\ViewSetting::init(); // Load .env file Core\Utils\dotEnv::loader(); // Load route handling use Core\Router\MatchRoute; use Core\Router\Response; use Core\Router\Request;
🚀 Getting Started
1. Define a Route
$route->get("/", function (Request $request, Response $response) { return $response->view("User/Home", [ 'name' => 'Codenova Framework' ]); });
2. Create a View
Create a file at:
app/Views/User/Home.php
<h1>Welcome, <?= $name ?> 👋</h1>
3. Create a Layout
File:
app/Views/Layout/Layout.php
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Codenova App</title> </head> <body> <?= $content ?> </body> </html>
4. Run a Local Server
Start PHP’s built-in server:
php -S localhost:8000 -t public
or use
php start.php
Open your browser at 👉 http://localhost:8000
You should see:
Welcome, Codenova Framework 👋
DB_NAME='hello'
DB_PASS=''
DB_HOST='localhost'''
DB_USER=root
⚙️ Using .env
You can store sensitive configuration in a .env file in your project root:
APP_ENV=local
APP_DEBUG=true
DB_HOST=localhost
DB_USER=root
DB_PASS=password
🚦 Advanced Routing
Dynamic Parameters
$route->get("/user/{id}", function (Request $request, Response $response) { echo "User ID: " . $request->params['id']; });
Multiple Handlers
$route->get("/post/{id}", [ function (Request $request, Response $response) { echo "Closure handler, method: " . $request->method; }, 'Post@show' // Controller@method ]);
404 Handling
$route->notFound([ function () { echo "Page not found, please try again."; }, 'ErrorController@notFound' ]);
✅ Validation Example
$valid = $response->validator([ "name" => ['require', 'isString', 'max:20', 'min:8'], "email" => ['require', 'isEmail', 'extension:gmail.com,hotmail.com'] ]); if ($valid->errors()) { return $response->view("User/Home", ['errors' => $valid->errors()]); } // Access validated data $validated = $valid->validated();
📂 Project Structure
app/
Controllers/
Database/
Helper/
Router/
Views/
Layout/
public/
index.php
vendor/
📜 License
This project is licensed under the MIT License.
⚡ With just a few lines of code, you can have routes, validation, and views working out of the box!
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-17