【问题标题】:Symfony2 - routing php app from vendorSymfony2 - 从供应商处路由 php 应用程序
【发布时间】:2015-01-12 17:06:33
【问题描述】:

我想从供应商处路由 php 脚本。 我使用 Composer 安装数据库管理 (https://github.com/vrana/adminer/)。 该应用程序的来源是:vendor/vrana/adminer/adminer/index.php

我想创建路由器来使用这个应用程序,例如当我调用 url myweb.com/adminer 时, 它应该加载该源:vendor/vrana/adminer/adminer/index.php

是否可以通过 routing.yml 做到这一点?像这样的:

adminer:
    resource: "Vendor/vrana/adminer/adminer/index.php"
    prefix:   /adminer

或者怎么可能?

【问题讨论】:

    标签: php symfony routing vendor


    【解决方案1】:

    真的很简单。

    创建常规路由,然后包含 adminer.php 并从控制器返回。不要忘记将此路由置于防火墙下

    在控制器中:

    use Symfony\Component\HttpFoundation\Response;
    public function mysqlClientAction() {
        return new Response(include_once $this->container->getParameter('kernel.root_dir') . '/Resources/views/adminer.php');
    }
    

    在routing.yml中

    admin_mysql_manager:
        path: /mysqlclient
        defaults: { _controller: YourBundle\Controller\YourController::mysqlClientAction}
    

    【讨论】:

      【解决方案2】:

      我通过模板解决了类似的问题,但我有捷克版本,只有一个文件:

      //app/Resources/views/adminer.html.php

      <?php
          include(__DIR__.'/../../../vendor/vrana/adminer/adminer/index.php');
       ?>
      

      和来自控制器的路由

      use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
      use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;    
      
      /**
       * @Route("/adminer", name="adminer")
       * @Template(engine="php")
       */
      public function adminerAction()
      {
          return $this->render('::adminers.html.php');
      }
      

      并把 adminer.php 并重命名为 /vendor/vrana/adminer/adminer/index.php 现在地址是您的站点/管理员

      【讨论】:

        【解决方案3】:

        通过 symfonys routing.yml 是不可能的,因为这需要启动应用程序内核,它位于 app.php 中。但是您可以将管理员设置为另一台服务器。

        如果你使用 apache 例如写/etc/apache2/sites-enabled/local

        <VirtualHost *:80>
            ServerName local.adminer
            DocumentRoot /YourPathToAdminer
            DirectoryIndex adminer.php
            <Directory /YourPathToAdminer>
                AllowOverride all
                Allow from all
            </Directory>
            LogLevel debug
        </VirtualHost>
        

        并在您的/etc/hosts 中添加某处

        127.0.0.1       local.adminer
        

        只需在浏览器中调用http://local.adminer 即可完成。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-04-27
          • 2013-05-03
          • 1970-01-01
          • 1970-01-01
          • 2017-08-07
          • 1970-01-01
          • 2015-09-11
          • 2010-09-12
          相关资源
          最近更新 更多