我想从供应商处路由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
或者如何做到这一点?
答案 0 :(得分: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}
答案 1 :(得分:0)
通过symfonys routing.yml
无法实现,因为这需要启动应用程序内核,该内核位于app.php
中。但您可以将adminer设置为另一台服务器。
如果您使用 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
,即可完成。
答案 2 :(得分:0)
我通过模板解决了类似问题,但我有捷克版,只有一个文件:
//应用程序/资源/视图/ adminer.html.php
<?php
include(__DIR__.'/../../../vendor/vrana/adminer/adminer/index.php');
?>
和来自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');
}
并将adminer.php重命名为/vendor/vrana/adminer/adminer/index.php 现在地址是yoursite / adminer