slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.98k stars 1.95k forks source link

integrate slim in drupal #273

Closed francescoagati closed 12 years ago

francescoagati commented 12 years ago

Hi, is possible integrate slim as a router inside a menu hook of drupal?

In lithium is possible using the normal hooks of drupal. see this file for an example of integration:

https://github.com/cliftonc/li3_drupal/blob/master/li3_drupal.module

First they define a hook menu


 function li3_drupal_menu() { 

    $items = array();

    $items[DRUPAL_LITHIUM_PATH] = array(
        'title' => t('Li3 Apps'),
        'page callback' => 'li3_drupal_index',
        'access arguments' => array('access li3'),    
        'access callback' => TRUE,
        'description' => 'Lithium Application',
        'expanded' => TRUE
    );    

    return $items;

  }

and after use the function li3_drupal_index for linkt the drupal url system with the router of li3


  /**
   * Apps list - non administrative
   */
  function li3_drupal_index() {

    // Lithium routing works based on the url parameter in the GET object
    // Drupal doesn't appear to require this, so re-wire based on q.
    $_GET['url'] = $_GET['q'];
    $response = lithium\action\Dispatcher::run(new lithium\action\Request())->body[0];

    $test = $_GET['q'];
    $json = 'json';
    $isjson = substr_compare($test, $json, -strlen($json), strlen($json)) === 0;
    if($isjson) {
        // Check if request is action.json          
        print $response;
        die;
    } else {
        // Return response in full
        return $response;
    }   

  }
codeguy commented 12 years ago

I'm not a Drupal expert. I encourage you to ask this question on the Slim Framework support forums. Closing this out.

http://help.slimframework.com

earlyburg commented 5 years ago

Hello: Please see my answer at Stack Overflow https://stackoverflow.com/questions/50504074/how-can-i-use-slim-micro-framework-inside-drupal/54674133#54674133

A load function can be used

require 'vendor/autoload.php';

function my_modulename_menu() { $items['my/page/%my_modulename_somefunction'] = array( 'page arguments' => array(2), 'access arguments' => array('access content'),

return $items;

}

function my_modulename_somefunction_load($var) {

$app = new \Slim\App; $request = request_path(); // set the Drupal request object here

if ($_SERVER['REQUEST_URI'] == "my/page/" . $var) {

  $app->get('/my/page/{passed}', function ($request, $response, array $args) {

  $stuff = $args['passed']

  // do something with your data here

  return $response->withJson($stuff);

});

$app->run();
exit;

}

}