PHPackages                             slim4-mod/mvc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. slim4-mod/mvc

ActiveSlim4-mod[Framework](/categories/framework)

slim4-mod/mvc
=============

Slim4-MVC tiny and faster MVC framework for PHP

041PHP

Since Sep 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/PhiHung908/Slim4-MVC)[ Packagist](https://packagist.org/packages/slim4-mod/mvc)[ RSS](/packages/slim4-mod-mvc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Slim4-Mod auto-route
--------------------

[](#slim4-mod-auto-route)

**Tác giả:** Phi Hùng -  - (VN) 0974 471 724

---

Slim4-MVC tiny and faster MVC framework for PHP

Các bổ sung và hiệu chỉnh là tối thiểu dể bạn có thể sử dụng MVC với slim4.

> *Đặc biệt:*
>
> - Có thể chạy nhiều website như từng module riêng lẻ trên một framework slimMVC duy nhất.
> - Nó sẽ nạp các route với tính chất động (dynamic) mỗi khi người dùng gõ vào một URL nào đó. Do vậy hệ thống sẽ hoạt động nhanh và ít tốn bộ nhớ vì không mất qui trình "init" chưa cần dùng đến.
> - View mặc định là PHP, bạn có thể dùng Smary (đặt phần mở rộng của view là .tpl) hoặc Twig (.twig) - Hệ thống sẽ nạp code động (lazy-dynamic load) khi bạn sử dụng một trong các loại kết xuất "view".

---

**Cài đặt:**

```
* Cài đặt lần đầu: Chuyển đến thư mục www (Document root), dán dòng lệnh dưới và bấm Enter (slimMVC là tên tùy chọn).

composer create-project slim4-mod/mvc:"dev-master" ./slimMVC

* Cập nhật core (khi có phiên bản mới):

composer require slim-mvc/core "dev-master"
```

##### \* Cấu hình Apache:

[](#-cấu-hình-apache)

**httpd.conf:**

```
Define SRVROOT "D:/Path-to/Apache24"
Define SRVROOTV "${SRVROOT}/../www"

```

**httpd-vhosts.conf:**

*localhost*

```

	Options Indexes FollowSymLinks
	AllowOverride All
	Require all granted

	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^ index.php [QSA,L]
	FallbackResource /index.php

	RewriteEngine on
	RewriteRule ^/sslim/(.*) /sslim/index.php/$1 [QSA,L]

	AddDefaultCharset UTF-8
	DocumentRoot "${SRVROOTV}"
	ServerName localhost
	ErrorLog "logs/localhost-error.log"
	CustomLog "logs/localhost-access.log" common

```

---

*subdir:*

```
Alias /sslim "${SRVROOTV}/slimMVC/src/web"

	ServerName localhost
	ErrorLog "logs/localhost-error.log"
	CustomLog "logs/localhost-access.log" common

	DocumentRoot "${SRVROOT}/slimMVC/src/web"

		Options Indexes FollowSymLinks
		AllowOverride None
		Require all granted

		RewriteCond %{REQUEST_FILENAME} !-f
		RewriteCond %{REQUEST_FILENAME} !-d
		RewriteRule ^ index.php [QSA,L]
		FallbackResource /index.php

	ServerName slim.local #cần khai báo hosts trong window: 127.0.0.1 slim.local
	ErrorLog "logs/slimMVC-error.log"
	CustomLog "logs/slimMVC-access.log" common

	DocumentRoot "${SRVROOTV}/slimMVC/src/web"

```

\--

> **Nếu bạn cài đặt lần đầu từ composer thì phần dưới đây đã được thiết lập sẵn, có thể bỏ qua phần này**
>
> **Quan trọng:** để ngăn truy xuất các thư mục con trong slimMVC, cần tạo slimMVC/.htacces với 1 dòng sau:
>
> Require all denied
>
> Đồng thời để "mở lại" chức năng truy xuất web, bạn cần tạo file .htacces trước thư mục "web-root" (ở ví dụ trên là thư mục src/.htacces) có 3 dòng sau:
>
> Require all granted RewriteEngine on RewriteRule "!web/" - \[L,F\] RewriteRule ^$ web/ \[L\] RewriteRule (.\*) web/$1 \[L\]

> **Chạy thử:**
>
> - Danh sách người dùng:
>
> - Người dùng có id = 2:
>
> - Danh sách người dùng với module **admin**:
>

```

Dữ liệu cấu hình ban đầu được lấy từ bộ nhớ, hãy tạo dữ liệu với bảng user và product...

và vào file \common\config\Repositories.php và đánh dấu XXX ở dòng:

'XXXdynamicRepository' => function( ...

để sử dụng cơ sở dữ liệu từ các bảng đã tạo.

```

##### Ảnh cấu trúc thư mục:

[](#ảnh-cấu-trúc-thư-mục)

[![common/docs/dir-struct.PNG](common/docs/dir-struct.PNG "Cấu trúc thư mục...")](common/docs/dir-struct.PNG)

##### Cách sử dụng:

[](#cách-sử-dụng)

> Dùng tiện ích dòng lệnh để tự động tạo cấu trúc file cần thiết cho model mới (NEW\_MODEL).
>
> ```
> new-model
>
> ```
>
>
>
> Sau khi chạy tiện ích xong bạn có thể gõ 'localhost/NEW\_MODEL' vào trình duyệt để thử ngay.
>
> Muốn tham khảo đủ tính năng, bạn cần làm 2 việc chính để sử dụng như MVC-framework:
>
> - 1- Đến thư mục src/models/NEW\_MODEL và thiết kế bổ sung ORM cho file NEW\_MODEL.php
> - 2- Tạo bảng tương thích với NEW\_MODEL.

- Qui định bắt buộc:
    - Cấu trúc thư mục như slim4 mẫu đang có. Tất cả thư mục là chữ thường, các file (class) là chữ cái đầu in hoa.
    - Tên các chức năng của "Product" phải có chữ đầu tiên là viết in hoa và nối phía sau là Action (ex: ListAction.php, RowAction.php, ...)

### HƯỚNG DẪN MỞ RỘNG

[](#hướng-dẫn-mở-rộng)

- **Tách website thành từng module:**

> Bạn có thể mở nhiều web site trên một framework slimMVC, hãy thực hiện các bước:
>
> 1- Khai báo tên module trong file common/config/prs4-alias.php (mẫu như dòng admin đã có trong file)
>
> 2- Copy thư mục template-web (hoặc backend, frontend hoặc thư mục nào đó của bạn) thành một bản mới.
>
> 3- Đổi tên thư mục vừa copy thành tên giống module đã khai báo ở bước 1.
>
> Sau khi hoàn thành, bạn có thể gõ vào *localhost/**admin**/product/list*
> (**admin** là module đã có sẵn, hãy thay nó bằng tên module của bạn)

- **Assets cho css, js và image -** Hệ thống sẽ tự nạp assets theo một trong 2 cách sau:

> a- Nạp class trực tiếp trong file action nếu bạn có khai báo constructor và class (xem mẫu product/listAction.php)
>
> b- Nạp từ file xxx\\controllers\\xxx\\auto\_gen\\Asset.php
>
> - Khai báo AssetClass cho hai cách trên là giống nhau, hãy tham khảo mẫu ListAction và RowAction trong .../product)

---

> *Chú thich:* Các tính năng đang trong quá trình thiết kế do vậy cần sự đóng góp của mọi người. Thanks!

---

*Tác giả: Phi-Hùng -  - Readme v.1.3*

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e8467443a275c0c04a9730ced053bc9c922a3667e58bff388e04e68c68036069?d=identicon)[PhiHung908](/maintainers/PhiHung908)

---

Top Contributors

[![PhiHung908](https://avatars.githubusercontent.com/u/167226939?v=4)](https://github.com/PhiHung908 "PhiHung908 (1 commits)")

### Embed Badge

![Health badge](/badges/slim4-mod-mvc/health.svg)

```
[![Health](https://phpackages.com/badges/slim4-mod-mvc/health.svg)](https://phpackages.com/packages/slim4-mod-mvc)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
