2017 © Pedro Peláez
 

library framework

image

slimmy/framework

  • Thursday, September 11, 2014
  • by emsifa
  • Repository
  • 0 Watchers
  • 0 Stars
  • 40 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Slimmy (mini) Framework, (*1)

slimmy-framework

Mini (H)MVC framework based on Slim micro framework combined with illuminate/database Laravel for model and Twig template engine for view., (*2)

It is just instant way to create Slim project with simple (H)MVC architecture., (*3)

Indonesian? nih README versi Indonesianya, (*4)

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:, (*5)

`composer create-project slimmy/framework yourprojectdirname --prefer-dist`

After finish installation, open localhost/yourprojectdirname/public in your browser., (*6)

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., (*7)

For example, you want to create some actions to manage user, (*8)

<?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:, (*9)

// 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., (*10)

For example, you have users table on your database, so the User model file might look like this:, (*11)

<?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, (*12)

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., (*13)

Rendering a view in controller, (*14)

<?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, (*15)

// 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, (*16)

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., (*17)

by default modules are located on app/modules., (*18)

Module Directory Structure

Basically, module structure might look like this, (*19)

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]., (*20)

For example, if you want render form-edit-user.twig in User module., (*21)

$this->app->render("@User/form-edit-user.twig", $data);

More from official documentation

The Versions

11/09 2014

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

11/09 2014
26/08 2014
24/08 2014
10/08 2014