Welcome to php-mvc, a minimal MVC framework designed to streamline your PHP development process. This lightweight framework offers essential features for building web applications while maintaining simplicity and ease of use.
php-library version 0.33 now end support for php 7.4. If you strill using php 7.4 use php-library 0.32.x, this version still accept bug and security update (small feature for improving performance).
- MVC structure
- Application Container (power with php-di)
- Router Support
- Models builder
- Query builder
- CLI command
- Service Provider and Middleware
- Templator (template engine)
- Create Your Application:
composer create-project sonypradana/php-mvc project-name
- Navigate to Your Project:
cd project-name
- Build Your Assets:
npm install
npm run build
- Serve Your Application:
php cli serve
# Create migration schema
php cli make:migration profiles
php cli db:create # skip if database already exists
php cli migrate
# Create a model
php cli make:model Profile --table-name profiles
# Create controller (or API services)
php cli make:controller Profile
php cli make:services Profile
# Presenter for HTML response
php cli make:view profile
// 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
]);
}
Api ready to go http://localhost:8080/api/profile/index
.
// 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);
Optimeze by cached Application.
# cache view compiler
php cli view:cache
# cache application config
php cli config:cache
php-mvc is open-source software licensed under the MIT license.