Slimore
The fully (H)MVC framework based on the Slim PHP Framwork v2.6.x ., (*1)
Install
Require php >=5.4.0 ., (*2)
composer.json :, (*3)
{
"require" : {
"slimore/slimore" : "*"
}
}
Install :, (*4)
$ composer install
Directory structure
Single module :, (*5)
/
app/
controllers/
models/
views/
configs/
routes.php
settigns.php
public/
.htaccess
index.php
vendor/
...
composer.json
Multi modules :, (*6)
/
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
Usige
.htaccess :, (*7)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
index.php :, (*8)
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();
```
Model :
```php
Using Eloquent ORM / Model : [http://laravel.com/docs/5.0/eloquent](http://laravel.com/docs/5.0/eloquent)
View :
<title><?=$title?></title>
<?=$var?>
<?php if ($exp) : ?>
<?php else : ?>
<?php endif; ?>
Controller :
<?php, (*9)
// Multi-module
//namesapce Frontend\Controllers;, (*10)
use \Slimore\Database\Manager as DB;, (*11)
class IndexController extends \Slimore\Mvc\Controller
{
public function index()
{
// Using model, same Laravel
$article = Article::find(1);, (*12)
// query builder
$news = $this->db->table('news')
->select(['nid', 'cid', 'title', 'content', 'add_time'])
->where(['cid' => 0])
->orderBy('nid', 'DESC')
->get();
//print_r($news);
// Basic database usage, same Laravel
$results = DB::select('select * from users where id = ?', [1]);
// Slim application methods
// request
$get = $this->request->get();
// response
//$this->response->headers->set('Content-Type', 'application/json');
// view
$this->view->setData(array(
'color' => 'red',
'size' => 'medium'
));
// render views/index.php
$this->render('index', [
'title' => 'Hello world!' . $article->title,
'article' => $article
]);
// output json
/*$this->json([
'status' => 200,
'message' => 'xxxxxx',
'data' => $article
]);*/
}
}
```, (*13)
Using Slim : http://docs.slimframework.com/, (*14)
Dependents
Components
- Captcha
- Debug\Simpler
- Functions
- FileCache
- Http\Client
- Image\Gd
- Log\Writer
- Pagination
- Uploader
- ...
Changes
Change logs, (*15)
License
The MIT License., (*16)
Copyright (c) 2015 Pandao, (*17)