PHP Classes
elePHPant
Icontem

Slim Starter: Build MVC Web applications based on Slim framework

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files Documentation   Screenshots Screenshots   View files View files (91)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2014-05-29 (1 year ago) RSS 2.0 feedNot enough user ratingsTotal: 402 All time: 6,024 This week: 1,124Up
Version License PHP version Categories  
slim-starter 1.0.0MIT/X Consortium ...5.3PHP 5, Libraries, Design Patterns
Description Author  

This package can be used to Build MVC Web applications based on the Slim framework.

It provides simplified means to create Web applications defining routes, providing base classes for models and controllers, and using Twig as template engine for the views.

Picture of ikhsan
Name: ikhsan <contact>
Classes: 2 packages by
Country: Indonesia Indonesia
Age: 26
All time rank: 125118 in Indonesia Indonesia
Week rank: 184 Up2 in Indonesia Indonesia Up

Details provided by the author  

SlimStarter

SlimStarter is a bootstrap application built with Slim Framework in MVC architecture, with Laravel's Eloquent as database provider (Model) and Twig as template engine (View).

Additional package is Sentry as authentication provider and Slim-facade which provide easy access to underlying Slim API with static interface like Laravel syntax (built based on Laravel's Facade).

Showcase

You can test SlimStarter in live site by visiting here : (shared hosting) http://slimstarter.xsanisty.com (pagodabox) http://slimstarter.gopagoda.com

with username admin@admin.com and password password.

Installation

> You can now install SlimStarter on pagodabox via App Cafe https://pagodabox.com/cafe/ikhsan017/slimstarter

1 Manual Install

You can manually install SlimStarter by cloning this repo or download the zip file from this repo, and run composer install. ` $git clone https://github.com/xsanisty/SlimStarter.git . $composer install `

2 Install via composer create-project

Alternatively, you can use composer create-project to install SlimStarter without downloading zip or cloning this repo.

composer create-project xsanisty/slim-starter --stability="dev"

3 Setup Permission

After composer finished install the dependencies, you need to change file and folder permission. ` chmod -R 777 app/storage/ chmod 666 app/config/database.php `

4 Configure and Setup Database

You can now access the installer by pointing install.php in your browser ` http://localhost/path/to/SlimStarter/public/install.php `

Configuration

Configuration file of SlimStarter located in app/config, edit the database.php, cookie.php and other to match your need

Routing

Routing configuration is located in app/routes.php, it use Route facade to access underlying Slim router. If you prefer the 'Slim' way, you can use $app to access Slim instance

Route to closure `php Route::get('/', function(){ View::display('welcome.twig'); });

/ the Slim way */ $app->get('/', function() use ($app){ $app->view->display('welcome.twig'); }); `

Route to controller method `php / get method */ Route::get('/', 'SomeController:someMethod');

/ post method */ Route::post('/post', 'PostController:create');

/ put method */ Route::put('/post/:id', 'PostController:update');

/ delete method */ Route::delete('/post/:id', 'PostController:destroy'); `

Route Middleware `php / route middleware */ Route::get('/admin', function(){ //route middleware to check user login or redirect }, 'AdminController:index'); `

Route group `php / Route group to book resource */ Route::group('/book', function(){ Route::get('/', 'BookController:index'); // GET /book Route::post('/', 'BookController:store'); // POST /book Route::get('/create', 'BookController:create'); // Create form of /book Route::get('/:id', 'BookController:show'); // GET /book/:id Route::get('/:id/edit', 'BookController:edit'); // GET /book/:id/edit Route::put('/:id', 'BookController:update'); // PUT /book/:id Route::delete('/:id', 'BookController:destroy'); // DELETE /book/:id }); `

Route Resource this will have same effect on route group above like Laravel Route::resource `php / Route to book resource */ Route::resource('/book', 'BookController'); `

RouteController `php / Route to book resource */ Route::controller('/book', 'BookController');

/ * GET /book will be mapped to BookController:getIndex * POST /book will be mapped to BookController:postIndex * [METHOD] /book/[path] will be mapped to BookController:methodPath */ `

Model

Models are located in app/models directory, since Eloquent is used as database provider, you can write model like you write model for Laravel, for complete documentation about eloquent, please refer to http://laravel.com/docs/eloquent

file : app/models/Book.php `php class Book Extends Model{} ` >Note: Eloquent has some limitations due to dependency to some Laravel's and Symfony's components which is not included, such as remember(), paginate, and validation method, which is depend on Illuminate\Cache, Illuminate\Filesystem, Symfony\Finder, etc.

Controller

Controllers are located in app/controllers directory, you may extends the BaseController to get access to predefined helper. You can also place your controller in namespace to group your controller.

file : app/controllers/HomeController.php `php Class HomeController extends BaseController{

public function welcome(){
$this->data['title'] = 'Some title';
View::display('welcome.twig', $this->data);
}

} `

Controller helper

Get reference to Slim instance

You can access Slim instance inside your controller by accessing $app property `php $this->app; //reference to Slim instance `

Loading javascript assets or CSS assets

SlimStarter shipped with default master template with js and css asset already in place, to load your own js or css file you can use loadJs or loadCss , removeJs or removeCss to remove js or css, resetJs or resetCss to remove all queued js or css file.

/
 * load local js file located in public/assets/js/application.js
 * by default, it will be placed in the last list,
 * to modify it, use position option in second parameter
 * array(
 *      'position' => 'last|first|after:file|before:file'
 * )
 */
$this->loadJs('application.js', ['position' => 'after:jquery.js'])

/
 * load external js file, eg: js in CDN
 * use location option in second parameter
 * array(
 *      'location' => 'internal|external'
 * )
 */
$this->loadJs('http://code.jquery.com/jquery-1.11.0.min.js', ['location' => 'external']);

/ remove js file from the list */
$this->removeJs('user.js');

/ reset js queue, no js file will be loaded */
$this->resetJs();


/ load local css file located in public/assets/css/style.css */
$this->loadCss('style.css')

/ load external css file, eg: js in CDN */
$this->loadCss('//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css', ['location' => 'external']);

/

Publish PHP variable to javascript

You can also publish PHP variable to make it accessible via javascript (must extends master.twig) `php / publish the variable */ $this->publish('user', User::find(1)->toArray());

/ remove the variable */ $this->unpublish('user'); `

the user variable will be accessible in 'global' namespace `javascript console.log(global.user); `

Default variable available in template

View

Views file are located in app/views directory in twig format, there is master.twig with 'body' block as default master template shipped with SlimStarer that will provide default access to published js variable.

For detailed Twig documentation, please refer to http://twig.sensiolabs.org/documentation

file : app/views/welcome.twig `html {% extends 'master.twig' %} {% block body %} Welcome to SlimStarter {% endblock %}


#####Rendering view inside controller
If your controller extends the BaseController class, you will have access to $data property which will be the placeholder for all
view's data.

View::display('welcome.twig', $this->data); `

Hooks and Middlewares

You can still hook the Slim event, or registering Middleware to Slim instance in app/bootstrap/app.php, Slim instance is accessible in $app variable.

$app->hook('slim.before.route', function(){
    //do your hook
});

$app->add(new SomeActionMiddleware());

You can write your own middleware class in app/middlewares directory.

file : app/middlewares/SomeActionMiddleware.php `php class SomeActionMiddleware extends Middleware { public function call() { // Get reference to application $app = $this->app;

// Run inner middleware and application
$this->next->call();

// do your stuff
}

} `

In case autoloader cannot resolve your classes, do composer dump-autoload so composer can resolve your class location

Screenshots  
  • user_manager_module
  Files folder image Files  
File Role Description
Files folder imageapp (1 file, 6 directories)
Files folder imagepublic (3 files, 1 directory)
Files folder imagesrc (1 directory)
Accessible without login Plain text file Boxfile Data Information file for deploying on pagodabox cloud server
Accessible without login Plain text file Boxfile.install Data Information file for deploying on pagodabox cloud server
Accessible without login Plain text file composer.json Data package dependency information
Accessible without login Plain text file LICENSE Lic. License file
Accessible without login Plain text file migrate.php Example script for migrating basic db
Accessible without login Plain text file README.md Doc. basic documentation file

  Files folder image Files  /  app  
File Role Description
Files folder imagebootstrap (2 files)
Files folder imageconfig (6 files)
Files folder imagecontrollers (4 files, 1 directory)
Files folder imagemodels (1 file)
Files folder imagemodules (1 directory)
Files folder imageviews (2 files, 3 directories)
  Accessible without login Plain text file routes.php Appl. routing configuration

  Files folder image Files  /  app  /  bootstrap  
File Role Description
  Accessible without login Plain text file app.php Appl. startup configuration
  Accessible without login Plain text file start.php Appl. application bootstrapper

  Files folder image Files  /  app  /  config  
File Role Description
  Accessible without login Plain text file aliases.php Conf. alias configuration
  Accessible without login Plain text file cookies.php Conf. cookie configuration
  Accessible without login Plain text file database.php Conf. database configuration
  Accessible without login Plain text file sentry.php Conf. sentry authentication configuration
  Accessible without login Plain text file slim.php Conf. Slim configuration
  Accessible without login Plain text file twig.php Conf. twig configuration

  Files folder image Files  /  app  /  controllers  
File Role Description
Files folder imageAdmin (2 files)
  Accessible without login Plain text file BaseController.php Appl. Base controller
  Accessible without login Plain text file DocController.php Appl. Documentation controller
  Accessible without login Plain text file HomeController.php Appl. welcome page controller
  Accessible without login Plain text file InstallController.php Appl. Installation controller

  Files folder image Files  /  app  /  controllers  /  Admin  
File Role Description
  Accessible without login Plain text file AdminController.php Appl. Admin authentication Controller
  Accessible without login Plain text file BaseController.php Appl. Admin Base controller

  Files folder image Files  /  app  /  models  
File Role Description
  Accessible without login Plain text file User.php Appl. User Model

  Files folder image Files  /  app  /  modules  
File Role Description
Files folder imageUserGroup (1 file, 2 directories)

  Files folder image Files  /  app  /  modules  /  UserGroup  
File Role Description
Files folder imageControllers (2 files)
Files folder imageviews (2 directories)
  Accessible without login Plain text file Initialize.php Appl. UserGroup module initializer

  Files folder image Files  /  app  /  modules  /  UserGroup  /  Controllers  
File Role Description
  Accessible without login Plain text file GroupController.php Appl. Application script
  Plain text file UserController.php Class Class source

  Files folder image Files  /  app  /  modules  /  UserGroup  /  views  
File Role Description
Files folder imagegroup (1 file)
Files folder imageuser (3 files)

  Files folder image Files  /  app  /  modules  /  UserGroup  /  views  /  group  
File Role Description
  Accessible without login Plain text file index.twig Data Auxiliary data

  Files folder image Files  /  app  /  modules  /  UserGroup  /  views  /  user  
File Role Description
  Accessible without login Plain text file edit.twig Data Auxiliary data
  Accessible without login Plain text file form.twig Data Auxiliary data
  Accessible without login Plain text file index.twig Data Auxiliary data

  Files folder image Files  /  app  /  views  
File Role Description
Files folder imageadmin (5 files)
Files folder imagedocs (3 files)
Files folder imageinstall (2 files)
  Accessible without login Plain text file master.twig Data master template file
  Accessible without login Plain text file welcome.twig Data sample template file

  Files folder image Files  /  app  /  views  /  admin  
File Role Description
  Accessible without login Plain text file dashboard.twig Data base dashboard template
  Accessible without login Plain text file index.twig Data Auxiliary data
  Accessible without login Plain text file login.twig Data Auxiliary data
  Accessible without login Plain text file sidebar.twig Data Auxiliary data
  Accessible without login Plain text file topbar.twig Data Auxiliary data

  Files folder image Files  /  app  /  views  /  docs  
File Role Description
  Accessible without login Plain text file index.twig Data Auxiliary data
  Accessible without login Plain text file sidebar.twig Data Auxiliary data
  Accessible without login Plain text file topbar.twig Data Auxiliary data

  Files folder image Files  /  app  /  views  /  install  
File Role Description
  Accessible without login Plain text file configure_db.twig Data Auxiliary data
  Accessible without login Plain text file finish.twig Data Auxiliary data

  Files folder image Files  /  public  
File Role Description
Files folder imageassets (4 directories)
  Accessible without login Plain text file .htaccess Data apache rewrite script
  Accessible without login Plain text file index.php Appl. front controller
  Accessible without login Plain text file install.php Appl. install script

  Files folder image Files  /  public  /  assets  
File Role Description
Files folder imagecss (6 files, 1 directory)
Files folder imagefonts (2 files)
Files folder imageimages (2 files)
Files folder imagejs (4 files, 3 directories)

  Files folder image Files  /  public  /  assets  /  css  
File Role Description
Files folder imageplugins (4 directories)
  Accessible without login Plain text file bootstrap.css Data Auxiliary data
  Accessible without login Plain text file bootstrap.min.css Data Auxiliary data
  Accessible without login Plain text file custom.css Data Auxiliary data
  Accessible without login Plain text file font-awesome.css Data Auxiliary data
  Accessible without login Plain text file font-awesome.min.css Data Auxiliary data
  Accessible without login Plain text file sb-admin.css Data Auxiliary data

  Files folder image Files  /  public  /  assets  /  css  /  plugins  
File Role Description
Files folder imagedataTables (1 file)
Files folder imagemorris (1 file)
Files folder imagesocial-buttons (1 file)
Files folder imagetimeline (1 file)

  Files folder image Files  /  public  /  assets  /  css  /  plugins  /  dataTables  
File Role Description
  Accessible without login Plain text file dataTables.bootstrap.css Data Auxiliary data

  Files folder image Files  /  public  /  assets  /  css  /  plugins  /  morris  
File Role Description
  Accessible without login Plain text file morris-0.4.3.min.css Data Auxiliary data

  Files folder image Files  /  public  /  assets  /  css  /  plugins  /  social-buttons  
File Role Description
  Accessible without login Plain text file social-buttons.css Data Auxiliary data

  Files folder image Files  /  public  /  assets  /  css  /  plugins  /  timeline  
File Role Description
  Accessible without login Plain text file timeline.css Data Auxiliary data

  Files folder image Files  /  public  /  assets  /  fonts  
File Role Description
  Accessible without login Plain text file fontawesome-webfont.svg Data Auxiliary data
  Accessible without login Plain text file glyphicons-halflings-regular.svg Data Auxiliary data

  Files folder image Files  /  public  /  assets  /  images  
File Role Description
  Accessible without login Image file loader.gif Icon Icon image
  Accessible without login Image file logo.png Icon Icon image

  Files folder image Files  /  public  /  assets  /  js  
File Role Description
Files folder imageapp (2 files)
Files folder imagedemo (3 files)
Files folder imageplugins (4 directories)
  Accessible without login Plain text file bootstrap.js Data Auxiliary data
  Accessible without login Plain text file bootstrap.min.js Data Auxiliary data
  Accessible without login Plain text file jquery-1.10.2.js Data Auxiliary data
  Accessible without login Plain text file sb-admin.js Data Auxiliary data

  Files folder image Files  /  public  /  assets  /  js  /  app  
File Role Description
  Accessible without login Plain text file install.js Data Auxiliary data
  Accessible without login Plain text file user.js Data Auxiliary data

  Files folder image Files  /  public  /  assets  /  js  /  demo  
File Role Description
  Accessible without login Plain text file dashboard-demo.js Data Auxiliary data
  Accessible without login Plain text file flot-demo.js Data Auxiliary data
  Accessible without login Plain text file morris-demo.js Data Auxiliary data

  Files folder image Files  /  public  /  assets  /  js  /  plugins  
File Role Description
Files folder imagedataTables (2 files)
Files folder imageflot (5 files)
Files folder imagemetisMenu (1 file)
Files folder imagemorris (2 files)

  Files folder image Files  /  public  /  assets  /  js  /  plugins  /  dataTables  
File Role Description
  Accessible without login Plain text file dataTables.bootstrap.js Data Auxiliary data
  Accessible without login Plain text file jquery.dataTables.js Data datatable js plugin

  Files folder image Files  /  public  /  assets  /  js  /  plugins  /  flot  
File Role Description
  Accessible without login Plain text file excanvas.min.js Data excanvas for canvas ability in when not supported
  Accessible without login Plain text file jquery.flot.js Data jquery plugin for graphing
  Accessible without login Plain text file jquery.flot.pie.js Data support pie chart for flot
  Accessible without login Plain text file jquery.flot.resize.js Data support resize chart for flot
  Accessible without login Plain text file jquery.flot.tooltip.min.js Data support tooltip for flot

  Files folder image Files  /  public  /  assets  /  js  /  plugins  /  metisMenu  
File Role Description
  Accessible without login Plain text file jquery.metisMenu.js Data menu effect for admin dashboard

  Files folder image Files  /  public  /  assets  /  js  /  plugins  /  morris  
File Role Description
  Accessible without login Plain text file morris.js Data morris chart plugin
  Accessible without login Plain text file raphael-2.1.0.min.js Data raphael plugin for morris

  Files folder image Files  /  src  
File Role Description
Files folder imageSlimStarter (1 file, 4 directories)

  Files folder image Files  /  src  /  SlimStarter  
File Role Description
Files folder imageFacade (6 files)
Files folder imageMenu (3 files)
Files folder imageModule (3 files)
Files folder imageTwigExtension (1 file)
  Plain text file Bootstrap.php Class Application Bootstrapper class

  Files folder image Files  /  src  /  SlimStarter  /  Facade  
File Role Description
  Plain text file DatabaseFacade.php Class Database static proxy class
  Plain text file MenuManagerFacade.php Class Menu Manager static proxy class
  Plain text file ModuleManagerFacade.php Class Modue Manager static proxy class
  Plain text file ResponseFacade.php Class Response static proxy class
  Plain text file RouteFacade.php Class Route static proxy class
  Plain text file SentryFacade.php Class Sentry static proxy class

  Files folder image Files  /  src  /  SlimStarter  /  Menu  
File Role Description
  Plain text file MenuCollection.php Class Menu collection to manage menu item
  Plain text file MenuItem.php Class MenuItem class
  Plain text file MenuManager.php Class Menu manager for rendering ang manage menu collection

  Files folder image Files  /  src  /  SlimStarter  /  Module  
File Role Description
  Plain text file Initializer.php Class base modue initializer
  Plain text file Manager.php Class module manager
  Plain text file ModuleInterface.php Class Class source

  Files folder image Files  /  src  /  SlimStarter  /  TwigExtension  
File Role Description
  Plain text file MenuRenderer.php Class Twig extension for rendering menu

 Version Control Unique User Downloads Download Rankings  
 98%Total:402All time:6,024
 This week:0This week:1,124Up