2017 © Pedro Peláez
 

package wp-slim

Slim framework as Wordpress plugin

image

botnary/wp-slim

Slim framework as Wordpress plugin

  • Monday, November 7, 2016
  • by Botnary
  • Repository
  • 5 Watchers
  • 54 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 15 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Wordpress Slim framework plugin

I built this plugin from a need of using a micro framework as Slim but inside Wordpress., (*1)

Installation

Copy wp-slim-framework folder with all it's content's into /wp-content/plugins directory. From Wordpress administrator enable the plugin and you are ready to go. But keep in mind that after enabling this plugin Wordpress must use permalinks Settings -> Permalinks use any structure except default one and Save changes., (*2)

Usage

To use it all you have to do is to map your routes. This plugin will register your routes when action slim_mapping is triggered. This action has one argument which is the Slim object., (*3)

Example of usage:, (*4)

add_action('slim_mapping',function($slim){
    $slim->get('/slim/api/user/:u',function($user){
    printf("User is %s",$user);            
    });
});

Example of usage inside of a class:, (*5)

class Rest{
    function __construct(){
        add_action('slim_mapping',array(&$this,'slim_mapping');            
    }

    function slim_mapping($slim){
        //if needed the class context
        $context = $this;
        $slim->get('/slim/api/user/:u',function($user)use($context){
              $context->printUser($user);            
        });
        $slim->put('/slim/api/user/:id',function($id)use($context){
              $context->updateUser($id);
        });
        //.... and so on
    }

    function printUser($user){
        printf("User is %s",$user);
    }
}

The default base path of the url is /slim/api. Added the possibility to change the base path, it can be found in Settings -> Slim Framework. Note: All routes must have the default base path /slim/api or the one used here Settings -> Slim Framework. This is added to avoid misunderstandings with Wordpress permalinks., (*6)

The Versions

07/11 2016

dev-master

9999999-dev

Slim framework as Wordpress plugin

  Sources   Download

The Requires

 

by Constantin