首页 文章

Doctrine ConsoleRunner(与codeigniter集成)

提问于
浏览
2

我在关于如何将它与codeigniter集成的学说中遵循this tutorial .

在某些时候,本教程要求我创建一个cli-config.php文件 .

我确实在我的codeigniter根文件夹上创建了它 .

在该文件中,我添加了以下代码:

<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;

// replace with file to your own project bootstrap
require_once 'index.php'; // <------- what should i add here?

// replace with mechanism to retrieve EntityManager in your app
$entityManager = GetEntityManager();

return ConsoleRunner::createHelperSet($entityManager);

我不确定他们对“你自己的项目引导程序”是什么意思 . 我以为他们在讨论index.php,这是codeginiter的核心部分 .

通过命令行并位于Codeigniter根文件夹(我安装了作曲家)我做了“php vendor / bin / doctrine”,但是我收到了这个错误 .

<div id="container">
        <h1>A Database Error Occurred</h1>
        <p>Unable to connect to your database server using the provided settings.</p><p>Filename: core/Loader.php</p><p>Line Number: 346</p>    </div>

我感到迷茫 . 有人能帮我吗?

EDIT: Doctrine的安装和加载到我的codeigniter应用程序的方式似乎一切正常,因为我可以从应用程序访问doctrine entityManager .

我只是不知道我是否通过从codeigniter引用我的中央应用程序index.php来正确设置控制台应用程序 .

1 回答

  • 0

    我没有使用带有CI的Doctrine控制台组件,而是使用ZF1 . 但我认为配置步骤是一样的 .

    • require_once 'index.php'意味着您应该进行框架初始化,包括加载配置,模块,路由,服务(包括数据库)等 - 您在客户端应用程序中需要的所有内容 .

    • 使用步骤1中的设置初始化原则 .

    • configure命令

    • 运行控制台应用程序

    代码示例

    $application->bootstrap('doctrine2');                                           
    
    $configurationOptions = $application->getBootstrap()->getOptions();             
    $emArr = $application->getBootstrap()->getResource('doctrine2');                
    $em = $emArr['default'];                                                        
    
    $symfonyPath = $configurationOptions['resources']['doctrine2']['lib_dir'];      
    $symfonyPath .= '/Doctrine';                                                                                   
    
    $classLoader = new \Doctrine\Common\ClassLoader('Symfony', $symfonyPath);       
    $classLoader->register();                                                                                      
    
    $cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', Doctrine\ORM\Version::VERSION); 
    
    $helperSet = $cli->getHelperSet();                                                                             
    $helperSet->set(new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'db');
    $helperSet->set(new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em), 'em');
    $cli->setHelperSet($helperSet);                                                                                
    
    $cli->setCatchExceptions(true);                                                 
    $cli->addCommands(array(                                                        
        // DBAL Commands                                                            
        new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(),                   
        new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), 
        ...
    ));                                                                             
    $cli->run();
    

相关问题