2015-05-26 14 views
9

Tôi đang cố gắng sử dụng Doctrine ORM với Silex và tìm kiếm nó hoàn toàn kinh nghiệm bực bội, do thiếu tài liệu nhất quán.Dòng lệnh Doctrine ORM với Silex: Bạn đang thiếu tệp "cli-config.php" hoặc "config/cli-config.php" trong dự án của mình

Khi tôi chạy vendor/bin/doctrine tại giao diện điều khiển, tôi nhận được kết quả như sau:

đầu ra:

You are missing a "cli-config.php" or "config/cli-config.php" file in your 
project, which is required to get the Doctrine Console working. You can use the 
following sample as a template: 

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

// replace with file to your own project bootstrap 
require_once 'bootstrap.php'; 

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

return ConsoleRunner::createHelperSet($entityManager); 

Đây là tập tin composer.json tôi:

{ 
    "require": { 
     "silex/silex": "2.0.*@dev", 
     "symfony/yaml": "2.6.7", 
     "doctrine/dbal": "~2.2", 
     "dflydev/doctrine-orm-service-provider": "2.0.*@dev", 
     "khepin/yaml-fixtures-bundle": "~0.8.1" 
    }, 
    "config": { 
      "bin-dir": "bin" 
    } 
} 

Đây là mã php đăng ký dịch vụ Doctrine, v.v.

<?php 

use Doctrine\Common\Cache\ApcCache; 
use Doctrine\Common\Cache\ArrayCache; 
use Silex\Provider\DoctrineServiceProvider; 
use Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider; 

$app->register(new DoctrineServiceProvider(), array(
       'db.options' => array(// http://silex.sensiolabs.org/doc/providers/doctrine.html 
        'driver' => 'pdo_mysql', 
        'dbname' => 'foobar', 
        'host' => 'localhost', 
        'user' => 'root', 
        'password' => 'root', 
        'charset' => 'utf8' 
       ) 
      )); 

$app->register(new DoctrineORMServiceProvider(), 
       array(
         'db.orm.proxies_dir' => __DIR__.'/../cache/doctrine/proxy', 
         'db.orm.proxies_namespace' => 'DoctrineProxy', 
         'db.orm.cache' => !$app['debug'] &&extension_loaded('apc') ? new ApcCache() : new ArrayCache(), 
         'db.orm.auto_generate_proxies' => true, 
         'db.orm.entities' => array(array(
                 'type' => 'simple_yaml', 
                 'path' => __DIR__.'/src/Resources/config/doctrine', 
                 'namespace' => 'Foobar\Entity', 
                 )), 
       )); 

này được tập tin cấu hình của tôi (bin/cli-config.php)

<?php 

// retrieve EntityManager 
use Doctrine\ORM\Tools\Setup; 
use Doctrine\ORM\EntityManager; 
use Doctrine\ORM\Tools\Console\ConsoleRunner; 

$app = require_once __DIR__.'/../app/src/app.php'; 

$isDevMode = $app['debug']; 

$paths = $app['db.orm.entities']['path']; 
$config = Setup::createYAMLMetadataConfiguration($paths, $isDevMode); 
$entityManager = EntityManager::create($app['db.options'], $config); 

return ConsoleRunner::createHelperSet($entityManager); 

Tôi đang làm gì sai?

+1

di chuyển 'bin/cli-config.php' trong 'config/cli-config.php' – Federkun

+0

@Leggendario: Nó sẽ được tốt đẹp nếu điều này đã được docuented ở đâu đó (hoặc tôi đã bỏ lỡ nó)? Khi nó quay ra, điều này có vẻ là câu trả lời, do đó, gửi nó như là một câu trả lời, vì vậy tôi có thể chấp nhận nó. –

Trả lời

8

Bạn cần di chuyển bin/cli-config.php trong config/cli-config.php.

Rất tiếc, tôi chưa tìm thấy tài liệu về nó. Tôi đã mở doctrine/dbal/bin/doctrine-dbal.php và kiểm tra cách hoạt động của nó.

+1

phải làm gì nếu tôi không có tệp 'cli-config.php' trong thư mục bin? – fonjeekay

0

Cả cli-config.phpbootstrap.php nên được đặt trong cùng một thư mục . Họ đang làm việc cho tôi nếu tôi đặt chúng ở gốc của dự án zend của tôi hoặc trong thư mục root-> config.

Sau đó, orm: lệnh chuyển đổi ánh xạ trong thiết bị đầu cuối trên máy mac chạy thành công.

./vendor/bin/doctrine orm:convert-mapping --namespace="Quiz\Model\Entity" --force --from-database annotation ./module/Quiz/src/Model/ 
Các vấn đề liên quan