snugphp/starter
最新稳定版本:v1.0.0
Composer 安装命令:
composer create-project snugphp/starter
包简介
A simple PHP framework
README 文档
README
A lightweight, fast, and elegant PHP framework starter kit for modern web development.
🚀 Overview
snugPHP Starter is the boilerplate for creating applications with the snugPHP framework. It provides the essential directory structure and configuration to get you started immediately.
Why snugPHP?
- ⚡ Lightning Fast - Minimal overhead, maximum performance
- 🎯 Auto Routing - Convention over configuration
- 🔧 Query Builder - Elegant database operations without models
- 🛠️ Rich Helpers - 50+ helper functions for common tasks
- 🔌 Middleware Support - Secure and modular request handling
- 📦 Zero Bloat - Only what you need, nothing more
📁 Directory Structure
your-project/
├── index.php # Application entry point
├── .env # Environment variables
├── composer.json # Dependencies & autoloading
│
├── app/ # Your application code
│ ├── config/ # Configuration files
│ │ ├── database.php # Database configuration
│ │ └── app.php # App settings
│ ├── controllers/ # Controller classes
│ │ ├── HomeController.php
│ │ └── ...
│ ├── middlewares/ # Middleware classes
│ │ └── AuthMiddleware.php
│ ├── views/ # Views & Layouts
│ │ ├── layouts/ # Master layouts
│ │ └── pages/ # Page templates
│ │ ├── home.php
│ │ └── ...
│ └── route.php # Manual route definitions
│
├── assets/ # Static files
│ ├── css/
│ ├── js/
│ └── images/
│
└── vendor/ # Composer dependencies (includes framework core)
🔧 Installation
To create a new project using snugPHP:
composer create-project snugphp/starter my-project
Requirements
- PHP >= 7.4
- MySQL/MariaDB
- Apache/Nginx with mod_rewrite enabled
- Composer
Quick Start
-
Navigate to your project directory:
cd my-project -
Configure Environment:
The installation should have created a
.envfile from.env.example. If not, copy it manually:cp .env.example .env
Update
.envwith your database credentials. -
Start development server:
php -S localhost:8000
Visit
http://localhost:8000in your browser.
🎯 Routing
snugPHP supports both manual routing and automatic routing.
Auto Routing
When APP_AUTO_ROUTING is enabled in .env (or config), URLs automatically map to controllers:
URL Pattern: /controller/method/param1/param2
/ → HomeController->index()
/user/index → UserController->index()
/user/show/123 → UserController->show(123)
/user/delete/123 → UserController->delete(123)
Manual Routing
Define custom routes in app/route.php:
use Core\Router; $router = new Router(); $router->get('/', function() { view('home'); }); $router->get('/user/index', [UserController::class, 'index']); $router->post('/user/store', [UserController::class, 'store']); $router->delete('/user/delete/{id}', [UserController::class, 'delete']); return $router;
🎮 Controllers
Create controllers in app/controllers/.
namespace App\Controllers; class UserController { public function index() { $users = db('users')->get(); view('users/index', ['users' => $users]); } public function store() { $user = db('users')->insert([ 'name' => 'John Doe', 'email' => 'john@example.com', 'password' => 'password', ]); } public function delete($id) { db('users')->where('id', $id)->delete(); } }
🗄️ Database
Access the database using the global db() helper.
// Select $users = db('users')->where('status', 'active')->get(); // Insert $id = db('users')->insert(['name' => 'John', 'email' => 'john@example.com']); // Update db('users')->where('id', 1)->update(['name' => 'Jane']); // Delete db('users')->where('id', 1)->delete();
👁️ Views
Views are located in app/views/pages/ and layouts in app/views/layouts/.
// Render 'app/views/pages/home.php' view('home', ['title' => 'Welcome']);
❓ Help
For more detailed documentation, check the core framework repository or the helper functions available in vendor/snugphp/framework.
📚 Best Practices
Controller Guidelines
- Keep controllers thin
- Use meaningful method names
- Return early for invalid input
- Use helper functions
Database Guidelines
- Always use query builder or prepared statements
- Index frequently queried columns
- Use transactions for multiple operations
- Close connections when done
Security Guidelines
- Validate all user input
- Escape output in views
- Use CSRF protection
- Never trust user input
- Keep framework updated
Performance Tips
- Enable OPcache in production
- Use database indexing
- Minimize database queries
- Cache frequently accessed data
- Optimize images and assets
🤝 Contributing
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch
- Make your changes
- Write tests if applicable
- Submit a pull request
📄 License
snugPHP is open-source software licensed under the MIT license.
💬 Support
- Documentation: https://github.com/Rabbi728/snugPHP/blob/master/readme.md
- Issues: https://github.com/Rabbi728/snugPHP/issues
- Email: rabbiahamed0728@gmail.com
🎉 Credits
Created with ❤️ by the snugPHP Team
Built for developers who value:
- Speed over complexity
- Simplicity over bloat
- Productivity over configuration
Happy coding with snugPHP! 🚀
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-03