PHP code example of sonypradana / php-mvc

1. Go to this page and download the library: Download sonypradana/php-mvc 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/ */

    

sonypradana / php-mvc example snippets


// database/migration/<timestamp>_profile.php

Schema::table('profiles', function (Create $column) {
    $column('user')->varChar(32);
    $column('real_name')->varChar(100);

    $column->primaryKey('user');
});

// app/Controller/ProfileController.php

public function index(MyPDO $pdo): Response
{
    return view('profiles', [
        'name' => Profile::find('pradana', $pdo)->real_name
    ]);
}

// app/services/ProfileServices.php

public function index(MyPDO $pdo): array
{
    return [
        'name'   => Profile::find('pradana', $pdo)->real_name,
        'status' => 200,
        'header' => []
    ];
}

// resources/views/profile.template.php

{% extend('base/base.template.php') %}

{% section('title', 'hay {{ $name }}') %}

{% section('content') %}
<p>{{ $name }}</p>
{% endsection %}

// route/web.php

Router::get('/profile', Profile::class);
bash
php cli serve