slimmy / framework
Requires
- php: >=5.3.10
- illuminate/validation: 4.1.*
- itsgoingd/slim-facades: 1.0
- rakit/slimmy: 0.*
This package is auto-updated.
Last update: 2019-02-20 19:42:22 UTC
README
slimmy-framework
Mini (H)MVC framework based on Slim micro framework combined with illuminate/database Laravel for model and Twig template engine for view.
It is just instant way to create Slim project with simple (H)MVC architecture.
Indonesian? nih README versi Indonesianya
Features
- powerful Eloquent ORM for Models.
- beautiful Twig Template Engine for Views.
- simple Modular System.
- great Laravel Validator.
Installation
First, make sure you have composer installed on your machine, and follow steps below:
-
open terminal or cmd(in Windows)
-
go to your based project directory(eg: htdocs in XAMPP, or www in WAMP)
-
run composer command below:
composer create-project slimmy/framework yourprojectdirname --prefer-dist
After finish installation, open localhost/yourprojectdirname/public
in your browser.
Basic Guides
Controller
Controller is a Class that grouping some actions/methods in your application, and these actions/methods can be called via Route. Controller files located in app/controllers
.
For example, you want to create some actions to manage user
<?php // app/controllers/UserController.php class UserController extends BaseController { public function pageManageUsers() { // some statements to create page manage users } public function addUser() { // some statements to add new user } }
And you can call these actions in your route file by:
// public/index.php // call action UserController->pageManageUser // when user landing on [site]/index.php/user/manage $app->get("/user/manage", "UserController:pageManageUsers"); // call action UserController->addUser // when user post something to [site]/index.php/user/add $app->post("/user/add", "UserController:addUser");
Model
Models are PHP classes that are designed to simplify interact with your table in your database. Model files located in app/models
directory. To make your model work, you must create at least one database connections on your app/configs/database.php
file.
For example, you have users
table on your database, so the User model file might look like this:
<?php // app/models/User.php use Illuminate\Database\Eloquent\Model; class User extends Model { protected $table = 'users'; }
this framework using Eloquent laravel for Model, so you can read full documentation about using Eloquent here
View
View basically is a file that contain HTML, css or js code that rendered to browser as a web page. View files by default is located on app/views
directory. This framework use twig as View, so you should use .twig
as extension.
Rendering a view in controller
<?php // app/controllers/UserController.php // example rendering 'app/views/manage-users.twig' via controller class UserController extends BaseController { public function pageManageUsers() { $data = array( // variables you want to creates in view ); $this->app->render("manage-users.twig", $data); } }
Rendering a view by Closure in Route
// public/index.php // example rendering 'app/views/manage-users.twig' via Route Closure $app->get("/users/manage", function() use ($app) { $data = array( // variables you want to creates in view ); $app->render("manage-users.twig", $data); });
For documentation about twig syntax, you can find it in twig official site here
Working with module
Module basically is a directory that contain their own controllers
, models
, and views
files.
Module used if you want to distribute tasks with your development team, crew A focused on module User, crew B focused on module Post, etc. And it can also simplify to migrate a part of your slimmy application to another slimmy application.
by default modules are located on
app/modules
.
Module Directory Structure
Basically, module structure might look like this
yourmodule
|- controllers
| |- YourModuleController.php
|
|- models
| |- YourModuleModel.php
|
|- views
| |- your-module-view.twig
|
|- migrators
| |- YourModuleMigrator.php
Call Module Controller action/method from Route
// public/index.php $app->get("/your-route", "@YourModuleName/YourModuleController:methodName");
Rendering Module View
Rendering module view is little bit different, because view in the module have it's own namespace. So, you should call these views in format @[ModuleName]/[viewpath/viewname.twig]
.
For example, if you want render form-edit-user.twig
in User
module.
$this->app->render("@User/form-edit-user.twig", $data);
More from official documentation
- Routing: http://docs.slimframework.com/#Routing-Overview
- Rendering a view: http://docs.slimframework.com/#Rendering
- Twig for view: http://twig.sensiolabs.org/
- Eloquent Model: http://laravel.com/docs/eloquent
- Validation: http://laravel.com/docs/validation