Welcome to Webby
Webby is a "lego-like" PHP framework that allows you to build APIs, Console/CLI and Web Applications in a modular architecture.
Note
Webby is built on CodeIgniter 3's proven core with modern PHP features. If you're familiar with CI3, you'll feel right at home.
What is Webby?
Webby aims to be a "lego-like" PHP framework that allows you to build APIs, Console/Cli and Web Applications in a modular architecture, that can also integrate other features from existing PHP frameworks or other PHP packages with ease.
Key Features
- Easy and Improved Routing - Intuitive syntax with support for RESTful APIs
- HMVC First Architecture - Build modular, maintainable applications
- Multiple Application Types - APIs, Console Apps, or Web Applications
- Easy Integration - Works with other frameworks and packages
- Modern PHP Support - Full support for PHP 8.0 through 8.4
Quick Example
Here's a simple example of defining routes in Webby:
// routes/api.php
Route::get('/api/users', 'UserController::index');
Route::post('/api/users', 'UserController::create');
Route::put('/api/users/:id', 'UserController::update');Warning
Always set the correct base URL in production to avoid routing issues.
Next Steps
Ready to get started? Check out the [Installation](<?= url('docs/getting-started/installation') ?>) guide.
Key Features
- Easy and Improved Routing - Intuitive syntax with support for RESTful APIs
- HMVC First Architecture - Build modular, maintainable applications
- Multiple Application Types - APIs, Console Apps, or Web Applications
- Easy Integration - Works with other frameworks and packages
- Modern PHP Support - Full support for PHP 8.0 through 8.4
Installation
The recommended way to install Webby is through Composer. Make sure you have Composer installed on your system.
System Requirements
- PHP 8.0 or newer (PHP 8.3 or 8.4 recommended)
- Composer 2.x
- MySQL 5.7+ or PostgreSQL 10+ (if using database)
- Apache or Nginx web server
Create a New Project
To create a new Webby project, run the following command:
$ composer create-project sylynder/webby my-projectReplace my-project with your desired project name.
Directory Structure
After installation, your project will have the following structure:
my-project/
├── app/
│ ├── config/
│ ├── controllers/
│ ├── models/
│ ├── views/
│ └── routes.php
├── modules/
├── public/
│ └── index.php
├── vendor/
│ └── sylynder/
│ └── engine/
└── composer.jsonQuick Start
Let's create your first endpoint in Webby. We'll build a simple API that returns user data.
Step 1: Define a Route
Open app/routes.php and add the following route:
// app/routes.php
Route::get('/api/users', 'UserController@index');
Route::get('/api/users/:id', 'UserController@show');Step 2: Create a Controller
Create a new file app/controllers/UserController.php:
// app/controllers/UserController.php
class UserController extends CI_Controller {
public function index() {
$users = [
['id' => 1, 'name' => 'John Doe'],
['id' => 2, 'name' => 'Jane Smith']
];
$this->output
->set_content_type('application/json')
->set_output(json_encode($users));
}
public function show($id) {
$user = ['id' => $id, 'name' => 'John Doe'];
$this->output
->set_content_type('application/json')
->set_output(json_encode($user));
}
}Step 3: Test Your API
Start the development server:
$ php -S localhost:8000 -t publicVisit http://localhost:8000/api/users in your browser or use curl:
$ curl http://localhost:8000/api/usersYou should see the JSON response with user data!
Configuration
Webby's configuration files are located in the app/config directory.
Environment Configuration
Set your environment in app/config/config.php:
// Development, Testing, or Production
$config['environment'] = 'development';Base URL
Configure your application's base URL:
$config['base_url'] = 'http://localhost:8000/';Important
Always set the correct base URL in production to avoid routing issues.
Create a new file app/controllers/UserController.php:
// app/controllers/UserController.php
class UserController extends CI_Controller {
public function index() {
$users = [
['id' => 1, 'name' => 'John Doe'],
['id' => 2, 'name' => 'Jane Smith']
];
$this->output
->set_content_type('application/json')
->set_output(json_encode($users));
}
public function show($id) {
$user = ['id' => $id, 'name' => 'John Doe'];
$this->output
->set_content_type('application/json')
->set_output(json_encode($user));
}
}