Symfony2 - routing php app from vendor

1k views Asked by At

I would like to route php script from Vendor. I used Composer to instal database managment (https://github.com/vrana/adminer/). Source of that app is: vendor/vrana/adminer/adminer/index.php

I would like to create router to use this app, for example when I call url myweb.com/adminer, it should load that source: vendor/vrana/adminer/adminer/index.php

Is it possible to do it via routing.yml ? Something like this:

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

Or how it possible to do it?

3

There are 3 answers

0
SBH On BEST ANSWER

It is not possible via symfonys routing.yml, since this needs the app kernel to be started, which is in app.php. But you can just set up adminer as another server.

If you use apache for example write in /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>

And in your /etc/hosts add somewhere

127.0.0.1       local.adminer

Just call http://local.adminer in your browser and you are done.

0
Radek Drlik On

I solved something similar through template but I have czech version, only one file:

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

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

and route from Controler

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');
}

and put adminer.php and rename into /vendor/vrana/adminer/adminer/index.php Now address is yoursite/adminer

0
Yuriy Yakubskiy On

It's really easy.

Create regular route and then include adminer.php and return it from controller. Do not forget to put this route under firewall

In controller:

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

in routing.yml

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