How do you organize large leisure APIs using the SLIM microplan?

I'm trying to use Slim, but I'm not sure if I can grow with a structure like this:

$app->group('/robots', function () use ($app) {

    include_once('controller/RobotController.php');

    $controller = new RobotController();

    $app->get('/:id', array($controller, 'getRobot'))
        ->conditions(array('id' => '[0-9]'));
});

I just want to have the model (bold) of the controller model (thick) and respond with json. But I do not want everything in one file, and I do not want to load every controller that I do not need.

What is your approach?

This URL unfortunately does not help: http://www.slimframework.com/2011/09/24/how-to-organize-a-large-slim-framework-application.html

+4
source share
1 answer

, $app- > group - , . , .

:

$app->group('/group1', function () use ($app) {

    $app->get('/route1', function () use ($app) {
        echo '<br> group1 route1';
    });

    echo '<br>group1';
});

$app->group('/group2', function () use ($app) {
    echo '<br> group2';
});

$app->group('/group3', function () use ($app) {
    echo '<br> group3';
});

/group1/route1

group1
group2
group3
group1 route1

, PSR. , .

$app->group('/robots', function () use ($app) {

    $app->get('/:id', 'controller\RobotController:getRobot')
        ->conditions(array('id' => '[0-9]'));
});

, "" "controller", .

, : paamayim ::, , Slim RobotController .

. "" , autoloader composer.json.

"autoload": {
    "psr-4": {
        "controller\\": "src/controllers_folder",
        "model\\": "src/doctrine_models"
    }
},

, .

, , , , , URL ( robots.php)

+1

All Articles