Skip to content

Latest commit

 

History

History
115 lines (90 loc) · 1.95 KB

documentation.md

File metadata and controls

115 lines (90 loc) · 1.95 KB

Simplex Framework Documentation

Table of Contents

  1. Getting Started
  2. Directory Structure
  3. Routing
  4. Controllers
  5. Models & ORM
  6. Views
  7. Middleware
  8. Configuration
  9. Database
  10. Logging

Getting Started

After installing the framework using:

composer create-project chiheb/simplex-framework your-project-name

Configure your environment by copying the example file:

cp .env.example .env

Controllers

Create controllers in app/Controllers:

namespace App\Controllers;

class HomeController
{
    public function index()
    {
        return view('home', ['title' => 'Welcome']);
    }
}

Models and ORM

Using CakePHP ORM:

namespace App\Models;

use Cake\ORM\Entity;

class User extends Entity
{
    protected array $_accessible = [
        'name' => true,
        'email' => true,
        'password' => true
    ];
}

Views

Create views in app/Views:

<!-- app/Views/home.php -->
<h1><?= $title ?></h1>

Configuration

Environment configuration in .env:

APP_NAME=SimplexApp
APP_ENV=local
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=simplex
DB_USERNAME=root
DB_PASSWORD=

Database

Configure your database in config/database.php:

return [
    'default' => env('DB_CONNECTION', 'mysql'),
    'connections' => [
        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST'),
            'database' => env('DB_DATABASE'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
        ]
    ]
];

Logging

Using Monolog for logging:

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$log = new Logger('app');
$log->pushHandler(new StreamHandler('storage/logs/app.log'));
$log->info('This is a log message');