Slimore 是一个基于 Slim 框架的完全 (H)MVC 框架。它封装多种常用的组件,可以更加方便的进行 Web 应用的开发。
主要特性:
完全 MVC,支持多模块应用;
集成了 Laravel Eloquent ORM / Model;
自带多种常用的组件(包括文件上传、缩略图、验证码等);
遵循 PSR-4 标准;
安装方法:
要求 PHP 5.4.0 及以上;
通过 Composer 安装,配置:
{ "require" : { "slimore/slimore" : "*" } }
执行安装命令:
composer install
目录结构:
单应用:
/ app/ controllers/ models/ views/ configs/ routes.php settigns.php public/ .htaccess index.php vendor/ ... composer.json
多模块应用:
/ app/ frontend/ controllers/ models/ views/ backend/ controllers/ models/ views/ api/ controllers/ models/ views/ ... configs/ routes.php settings.php public/ .htaccess index.php vendor/ ... composer.json
使用方法:
.htaccess 配置 :
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [QSA,L]
index.php
<?php define('APP_PATH', realpath(__DIR__ . '/../app') . DIRECTORY_SEPARATOR); define('BASE_URL', str_replace('index.php', '', $_SERVER['PHP_SELF'])); require __DIR__ . '/../vendor/autoload.php'; $app = new \Slimore\Mvc\Application([ 'debug' => true, 'path' => APP_PATH, 'baseURL' => BASE_URL, //'modules' => ['home', 'admin', 'api'], // Multi-Modules //'defaultModule' => 'home', 'autoloads' => [ APP_PATH . 'path/xx/xx' ] ]); //$app->dbConnection(); // if using database $app->get("/", function() { echo "Hello world!"; }); // Routes //$app->get('/news', 'NewsController:read'); // or $app->get('/news', controller('index', 'read')); //$app->get('/news', 'Home\Controllers\NewsController:read'); // or $app->get('/news', controller('news', 'read', 'Home\Controllers\\')); //$app->post('/news', 'Home\Controllers\NewsController:create'); //$app->put('/news/:id', 'Home\Controllers\NewsController:update'); //$app->delete('/news/:id', 'Home\Controllers\NewsController:delete'); // or /* $app->moduleNamespace('Home\Controllers\\', function($namespace, $app) { //echo $namespace; $ctl = 'IndexController'; //$app->get('/', $namespace . $ctl . ':index'); //$app->get('/news/:id', $namespace . $ctl . ':index'); $app->controller('index', function($controller, $app, $namespace) { //echo $controller . ', ' . $namespace; //$app->get('/news/:id', $namespace . $controller . ':index'); }, $namespace); });*/ // Auto routes => /:action, /:controller/:action, /:module/:controller/:action $app->autoRoute(); $app->run();