PHP code example of raoul / mvc-framework

1. Go to this page and download the library: Download raoul/mvc-framework library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

raoul / mvc-framework example snippets


use App\Http\Route;
use App\Http\Controllers\DemoController;

Route::get('url', [DemoController:class, 'method'], "name");
Route::post('url', [DemoController:class, 'method'], "name");
Route::put('url', [DemoController:class, 'method'], "name");
Route::delete('url', [DemoController:class, 'method'], "name");

Route::get('url/{id}/another/{param}', [DemoController:class, 'method'], "name");

Route::prefix('/demo')->group(function() {
  	Route::get('url', [DemoController:class, 'method'], "route");
    Route::get('url', [DemoController:class, 'method'], "anotherRouteInGroup");
});

Route::get('url', [DemoController:class, 'method'], "anotherRouteInGroup", middleware: "nameOfMiddleware");

Route::prefix('/demo')->group(function() {
  Route::get('/url', [DemoController:class, 'method'], "route");
}, ["middleware" => ["nameOfMiddleware"]]);

  private $routeMiddleware = [
    "nameOfMiddleware" => \App\Http\Middleware\YoureMiddlewareClass
  ];

class DemoController extends Controller
{
  public function demo()
  {
    // Redirect to different route
    $this->redirect('name_of_route');

    // Redirect with a message
    $this->redirect('name_of_route')->with('key', 'value');

    // Go to previous route
    $this->back();
  }
}

class DemoController extends Controller
{
  public function demo()
  {
    // Filename in resources folder
    $this->view('file');


  }
}

class User

protected $databaseTable = 'tablename';

   /**
   * Var used to store the database Table of the model
   */
  protected string $databaseTable;

  /**
   * Var used to keep track of tables primary key
   */
  protected string $primaryKey = 'id';

  /**
   * Var used to store all the columns that are allowed to be inserted
   */
  protected array $fillable = [];

  public function Demo()
  {
  // Using not Raw functions are **NOT SAFE** using this without sanitizing the user input is not recommended
    return Progress::select()->where('id = 1')->get();
    
    // using Raw functions are safer since it is using prepared statements with binding
    return Progress::select()->whereRaw('id = :id', [':id', 1])->get();
    
    // But you should still always sanitize the user input
  }

  public function Demo()
  {
    return Progress::query('SELECT * FROM users');
  }

->get();

  public function rules()
  {
    return [
      'username' => '

$redirect_if_failed = 'name_of_route';

  public function authorize()
  {
    return true;
  }
bash
$ php mvc serve
bash 
$ php mvc make:middleware NameOfTheMiddleware
bash
$ php mvc make:controller YoureNameOfTheController
bash
$ php mvc make:model YoureNameOfTheModel
bash
$ php mvc make:request NameOfRequestClass