[英]How to access Symfony Components in a custom main file
I am working to make a batch file which will get some data from DB and send email. 我正在制作一个批处理文件,它将从数据库中获取一些数据并发送电子邮件。 A folder
Batch
is created in the same level of app and web
. 在
app and web
的同一级别创建一个文件夹Batch
。 Now my question is - how to access DB and other controls out of controller. 现在我的问题是-如何从控制器之外访问数据库和其他控件。
I tried to import use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route; use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template;
我尝试导入
use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route; use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template;
use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route; use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template;
but it gives error saying no such files found. 但给出错误消息,提示未找到此类文件。
I don;t want it to be command/console app. 我不希望它成为命令/控制台应用程序。
My aim is to create a file which uses symfony components and Doctrine by staying outside bundle/controller. 我的目标是通过不使用捆绑软件/控制器来创建使用symfony组件和教义的文件。 How do I import files in the file?.
如何导入文件中的文件?
First I really recommend to create a Symfony Console Command for this. 首先,我真的建议为此创建一个Symfony控制台命令 。
But if you really want to create a file (lets say test.php
) in your document root, you can load a symfony service like this: 但是,如果您真的想在文档根目录中创建一个文件(比如说
test.php
),则可以加载一个symfony服务,如下所示:
<?php
require __DIR__.'/app/autoload.php'; // load the autoloader
$kernel = new AppKernel('prod', false); // create a kernel instance
$kernel->loadClassCache(); // load the class cache
$kernel->boot(); // boot the kernel which will initialise the container.
$myInstance = $kernel->getContainer()->get('myservice');
$myInstance->doWhatever();
PS: In there you should also be able to make use of all other symfony components. PS:在那里,您还应该可以使用所有其他symfony组件。
PPS: The Notice: Use of undefined constant OCI_COMMIT_ON_SUCCESS - assumed 'OCI_COMM IT_ON_SUCCESS'
error tells you that something is wrong with your oci8
extension try to reinstall/install or enable it again. PPS:
Notice: Use of undefined constant OCI_COMMIT_ON_SUCCESS - assumed 'OCI_COMM IT_ON_SUCCESS'
错误,告诉您oci8
扩展程序出现问题,请尝试重新安装/安装或再次启用它。 http://php.net/manual/en/oci8.installation.php http://php.net/manual/zh/oci8.installation.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.