limingxinleo/x-phalcon-router

a phalcon router component

1.0.1 2018-03-03 01:21 UTC

This package is auto-updated.

Last update: 2021-04-17 11:27:04 UTC


README

a phalcon router component

Build Status

安装

composer require limingxinleo/x-phalcon-router

配置

添加服务

<?php
 
use Xin\Phalcon\Router\Mvc\Router;

$di->setShared('router', function () {
    $router = new Router(false);
    // 普通路由
    $router->add('/index', 'Tests\\App\\Controllers\\Index::index');

    // 默认组使用方式
    $group = new \Phalcon\Mvc\Router\Group();
    $group->setPrefix('/test');
    $group->add('/index', 'Tests\\App\\Controllers\\Index::group');
    $router->mount($group);

    // 匿名函数使用方式
    $router->group(function () {
        $group = new \Phalcon\Mvc\Router\Group();
        $group->setPrefix('/test2');
        $group->add('/index', 'Tests\\App\\Controllers\\Index::group');

        return $group;
    });

    return $router;
});