SlimPhp 函数声明中的问题

Issue in the declaration of functions on SlimPhp

自从我开始发现 slim 之后,我 运行 遇到了一个问题,我不知道如何寻找解决方案,因为它非常难 运行ge。 基本上,如果我在路由调用另一个函数之后声明一个从路由调用的函数,则不会执行第一个函数。

API组

// API group
$app->group('/api/:key', function () use ($app) {

    //print all route
    $app->get('/all',function () use($app){
        echoRoutes();
    });
    // Library group
    $app->group('/themer', function () use ($app) {

         //get number of subscribed themer
        $app->get('/count','allowed',function (){
            echo "ciao";
        });
        //get information about the themer selected
        $app->get('/:id','getThemer'); //AFTER THIS ROUTES /ciao AND /themes NOT WORK

         $app->get('/ciao',function () use($app){
        echoRoutes();
    });

     // Get book with ID
        $app->get('/themes', function () use ($app) {
            $articles = R::findAll('users'); 
            $app->response()->header('Content-Type', 'application/json');
            echo json_encode(R::exportAll($articles));
        });

        //get number of submitted theme by themer
        //$app->get('/:id/themes','getSubmitedThemeById');


        //get information about selected theme
        //$app->get('/:id/themes/:theme','getThemeById');

        $app->get('/themes/:id/', function ($id) {
            $articles = R::find("users","id = ?",[$id]);
            echo json_encode(R::exportAll($articles));
        });

    });

});

具有函数的外部文件

//external file with function
function  getThemer($key,$id) { 
   $themer = R::find("themers","id = ?",[$id]);
   echo json_encode(R::exportAll($themer));
   return true;
}

function countThemer(){
    echo "count";
    $count =  R::exec( 'SELECT COUNT(id) FROM themers' );
    echo $count;
}

function allowed($key){
    $app = \Slim\Slim::getInstance();
    $params = $app->router()->getCurrentRoute()->getParams();
    if(!($params["key"]=="giulio"))
        $app->redirect ("http://google.com");

}

在路线 index.php/api/giulio/themer/1 之后调用 getThemer 并在路线 index.php/api/giulio/themer/ciaoindex.php/api/giulio/themer/themes 无效

在此先感谢您可能提供的帮助 欢迎对'general appea运行ce中的代码提出批评或评论

更改路线的顺序:

// API group
$app->group('/api/:key', function () use ($app) {

    //print all route
    $app->get('/all',function () use($app){
        echoRoutes();
    });
    // Library group
    $app->group('/themer', function () use ($app) {

         //get number of subscribed themer
        $app->get('/count','allowed',function (){
            echo "ciao";
        });

        $app->get('/ciao',function () use($app){
            echoRoutes();
        });

        // Get book with ID
        $app->get('/themes', function () use ($app) {
            $articles = R::findAll('users');
            $app->response()->header('Content-Type', 'application/json');
            echo json_encode(R::exportAll($articles));
        });

        //get number of submitted theme by themer
        //$app->get('/:id/themes','getSubmitedThemeById');


        //get information about selected theme
        //$app->get('/:id/themes/:theme','getThemeById');

        $app->get('/themes/:id/', function ($id) {
            $articles = R::find("users","id = ?",[$id]);
            echo json_encode(R::exportAll($articles));
        });

        //get information about the themer selected
        $app->get('/:id','getThemer');

    });

});