snugphp/starter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

PHP Version License

🚀 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

  1. Navigate to your project directory:

    cd my-project
  2. Configure Environment:

    The installation should have created a .env file from .env.example. If not, copy it manually:

    cp .env.example .env

    Update .env with your database credentials.

  3. Start development server:

    php -S localhost:8000

    Visit http://localhost:8000 in 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:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Write tests if applicable
  5. Submit a pull request

📄 License

snugPHP is open-source software licensed under the MIT license.

💬 Support

🎉 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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: CSS

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-03