dongqian2021 2016-12-12 09:38
浏览 32
已采纳

Silex 2 - 如何口动态路线? 与Silex的第1版一样

I have a project that use Silex 1.2 in addition to updating to version 2. But mounting routes dynamically in a controller no longer works. My new routes are not saved.

// routing.php
$app->get('/', 'App\\Controllers\\App::main')->bind('app_main');

// App.php
class App {
    function main(Application $app, Request $request) {
        $name = 'basic';
        $version = 1;

        $moduleClass = 'App\Core\Modules\\'.$name.'\v'.$version.'\\ControllerProvider';
        $app->mount($request->getPathInfo(), new $moduleClass($name, $version));

        $subRequest = Request::create(
            $app['url_generator']->generate('basic_1'),
            'POST'
        );

        return $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
    }
}

And my application can not find the new route, this code work with Silex 1.2... I can not find what has changed in version 2.

  • 写回答

1条回答 默认 最新

  • douzuqin3467 2016-12-12 10:49
    关注

    You need to flush the controller collection. After you mount them, call this:

    $app->flush();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 openwrt双栈NAT
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用