A simple, lightweight PHP and JavaScript framework for building web applications following the MVC architecture.
EasyGo is a minimalist PHP framework designed for simplicity and flexibility. It provides a clean structure for your web applications with essential features like routing, database abstraction, MVC architecture, template system, session management, and file handling.
- Routing System: Simple and flexible URL routing
- MVC Architecture: Clean separation of concerns
- Database Abstraction: Simple database operations with PDO
- Template System: Clean view rendering with layouts
- Session Management: Secure session handling
- File Handling: Easy file upload and management
- API Support: Built-in support for RESTful API development
.
├── composer.json # PHP dependencies
├── core/ # Framework core files
│ ├── Application.php # Main application class
│ ├── BaseController.php # Base controller class
│ ├── Request.php # HTTP request handling
│ ├── Response.php # HTTP response handling
│ ├── Router.php # URL routing
│ ├── Database/ # Database related classes
│ └── Utils/ # Utility classes
├── public/ # Publicly accessible files
│ ├── index.php # Application entry point
│ └── assets/ # CSS, JS, images, etc.
└── src/ # Application source code
├── routes.php # Route definitions
├── controllers/ # Application controllers
├── models/ # Application models
└── views/ # View templates
- PHP 7.4 or higher
- Composer
- MySQL or compatible database
You can create a new EasyGo project in two ways:
Option 1: Clone the repository
git clone https://github.com/yourusername/easygo-framework.git my-project
cd my-project
Option 2: Download the ZIP file
Download the ZIP file from GitHub and extract it to your project directory.
composer install
Copy the example environment file:
cp .env.example .env
Edit the .env
file with your database and application settings:
# Database connection settings
DB_DRIVER = mysql
DB_HOST = localhost
DB_PORT = 3306
DB_NAME = your_database_name
DB_USER = your_database_user
DB_PASSWORD = your_database_password
# Application settings
APP_ENV = development
APP_DEBUG = true
APP_URL = http://localhost
Create a new database and import the schema if available.
composer start
This will start the PHP development server at http://localhost:5000
.
Routes are defined in src/routes.php
. A typical route looks like:
// Page routes (rendering views)
$app->router->get('/', 'SiteController@home');
$app->router->get('/users-page', 'SiteController@usersPage');
// API routes
$app->router->get('/api/users', 'UserController@getUsers');
$app->router->post('/api/users', 'UserController@createUser');
Controllers are placed in src/controllers/
. A basic controller looks like this:
<?php
// filepath: src/controllers/UserController.php
require_once __DIR__ . '/../../vendor/autoload.php';
use app\core\BaseController;
use app\core\Database\BaseModel;
class UserController extends BaseController
{
private $userModel;
public function __construct()
{
$this->userModel = new BaseModel('users');
}
// API endpoint to get users data
public function getUsers($req, $res)
{
// Get users from database
$users = $this->userModel->read();
// Return JSON response
$res->setHeader('Content-Type', 'application/json');
echo json_encode([
'status' => 'success',
'data' => ['users' => $users]
]);
}
}
Views are placed in src/views/
. You can use layouts for consistent page structure:
<?php
// In a controller method:
$this->renderView('pages/users/index', [
'title' => 'Users List',
'description' => 'View all users in the system'
]);
// Or with a layout:
$this->renderWithLayout('main', 'pages/users/index', [
'title' => 'Users List',
'description' => 'View all users in the system'
]);
The framework provides a simple database abstraction layer:
// Create a model instance for a table
$userModel = new BaseModel('users');
// Create a new record
$userId = $userModel->create([
'username' => 'john_doe',
'email' => 'john@example.com'
]);
// Read records
$users = $userModel->read([
'order' => 'username ASC',
'limit' => 10
]);
// Update a record
$userModel->update(['status' => 'active'], [
'filters' => ['id' => 5]
]);
// Delete a record
$userModel->delete([
'filters' => ['id' => 5]
]);
- Use MVC Pattern: Keep controllers thin, business logic in models, and presentation in views.
- Validate Input: Always validate and sanitize user input.
- Use Prepared Statements: The database layer uses prepared statements to prevent SQL injection.
- Keep Routes Organized: Group related routes together.
- Use Layouts: Create reusable layouts for consistent page structure.
- User makes a request to
public/index.php
- Application bootstraps and loads environment variables
- Router matches the URL to a route
- Controller action is executed
- Response is returned to the user
The framework supports a separation of rendering and data fetching:
- Pages are initially rendered without data
- JavaScript fetches data from API endpoints
- UI is updated with the fetched data
- This approach allows for better separation of concerns
- White Screen of Death: Check your error logs and ensure
APP_DEBUG
is set totrue
during development. - Route Not Found: Ensure the route is properly defined in
src/routes.php
. - Database Connection Failed: Verify your database credentials in the
.env
file.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
EasyGo Framework was created by Kavinda.