2011-03-26 80 views
3

好了,我有一個文件夾層次Doctrine.php文件像這樣:學說2.0 Bootstrap?

 
\ 
    includes\ 
    Setup.php 
    Doctrine\ 
     Common\ 
     DBAL\ 
     ORM\ 
     Symfony\ 
     Doctrine.php 

我setup.php有以下幾點:

$rootPath = $_SERVER['DOCUMENT_ROOT']; 
$includePath = getcwd() . "\includes"; 
ini_set('include_path', '.'.PATH_SEPARATOR.$rootPath.PATH_SEPARATOR.$includePath); 

require_once 'includes\Doctrine\Doctrine.php'; 

我Doctrine.php是:

<?php 
/* 
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
* 
* This software consists of voluntary contributions made by many individuals 
* and is licensed under the LGPL. For more information, see 
* <http://www.doctrine-project.org>. 
*/ 

require_once 'Doctrine/Common/ClassLoader.php'; 

$classLoader = new \Doctrine\Common\ClassLoader('Doctrine'); 
$classLoader->register(); 

$classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'Doctrine'); 
$classLoader->register(); 

$configFile = getcwd() . DIRECTORY_SEPARATOR . 'cli-config.php'; 

$helperSet = null; 
if (file_exists($configFile)) { 
    if (! is_readable($configFile)) { 
     trigger_error(
      'Configuration file [' . $configFile . '] does not have read permission.', E_ERROR 
     ); 
    } 

    require $configFile; 

    foreach ($GLOBALS as $helperSetCandidate) { 
     if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) { 
      $helperSet = $helperSetCandidate; 
      break; 
     } 
    } 
} 

$helperSet = ($helperSet) ?: new \Symfony\Component\Console\Helper\HelperSet(); 

\Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet); 

現在,當我包括來自世界你好頁我setup.php,我得到以下警告:

 
Notice: Undefined index: argv in C:\xampp\htdocs\SpaceWars\includes\Doctrine\Symfony\Component\Console\Input\ArgvInput.php on line 53 

Warning: array_shift() expects parameter 1 to be array, null given in C:\xampp\htdocs\SpaceWars\includes\Doctrine\Symfony\Component\Console\Input\ArgvInput.php on line 57 

任何人都可以請指導我我做錯了什麼?我試着用谷歌搜索的警告,但似乎無法找到任何東西。

+0

你嘗試使用[沙盒(HTTPS ://github.com/doctrine/doctrine2/tree/master/tools/sandbox)例子? – meze 2011-03-26 18:53:09

+0

如果我完全誠實,對於如何/在哪裏放置Doctrine項目以及如何包含它並將其引導到我的應用程序中,我完全感到困惑。我什至不能在文件中找到告訴我如何去做的事情。 – 2011-03-26 18:56:51

+0

你應該發佈你的Doctrine.php文件。它需要根據您的環境進行定製。 – rojoca 2011-03-26 19:00:57

回答

4

你有沒有從從命令行運行的工具主義學說文件。你需要什麼,而不是類似於這樣:

use Doctrine\Common\ClassLoader, 
     Doctrine\ORM\Configuration, 
     Doctrine\ORM\EntityManager, 
     Doctrine\DBAL\Types\Type, 
     Doctrine\Common\Cache\ArrayCache, 
     Doctrine\DBAL\Logging\EchoSqlLogger; 


    // include the class loader directly 
    require_once __DIR__ . '/Common/ClassLoader.php'; 

    $doctrineClassLoader = new ClassLoader('Doctrine', __DIR__ . '/../'); 
    $doctrineClassLoader->register(); 

    // Set up caches 
    $config = new Configuration; 
    $cache = new ArrayCache; 
    $config->setMetadataCacheImpl($cache); 
    $config->setQueryCacheImpl($cache); 

    // Metadata Driver 
    $driverImpl = $config->newDefaultAnnotationDriver(array('/path/to/entities')); 
    $config->setMetadataDriverImpl($driverImpl); 

    // Proxy configuration 
    $config->setProxyDir(DB_PROXY_DIR); 
    $config->setProxyNamespace(DB_PROXY_NAMESPACE); 
    $config->setAutoGenerateProxyClasses(DB_PROXY_GEN); 

    // Database connection information 
    $connectionOptions = array(
     'driver' => 'pdo_mysql', 
     'user' => DB_USER, 
     'password' => DB_PASS, 
     'host' => DB_HOST, 
     'dbname' => DB_NAME, 
     'port' => DB_PORT 
    ); 

    // Create EntityManager 
    $em = EntityManager::create($connectionOptions, $config); 

$em是你用來保持和檢索實體的實體管理器。這是從這裏的文檔:http://www.doctrine-project.org/docs/orm/2.0/en/reference/configuration.html#obtaining-an-entitymanager

UPDATE在文件的頂部添加使用語句。這些都是必需的,以便在使用這些類時不需要完整的命名空間。

+0

感謝您的回覆,但是,我收到了一個「致命錯誤:類'ClassLoader'未找到C:\ xampp \ htdocs \ SpaceWars \ includes \第6行中的\ Doctrine \ Doctrine.php」這是新的ClassLoader 'Doctrine'... line:/ – 2011-03-27 03:28:49

+1

@Martin Blore - 我已經更新了答案,在頂部包含'use'語句,這些讓你可以在沒有完整命名空間的情況下使用類 – rojoca 2011-03-27 04:46:14

+1

再次感謝rojoca,只是邁出了一步PHP從數年的.NET開始,似乎無法理解大多數基礎知識 - 所以可能會退後一步並首先獲得一些基礎知識。 – 2011-03-27 11:51:00

0

argv的 - 是一個系統變量
如果從控制檯運行腳本,它必須存在

1

你的PHP版本上運行CGI不CLI

請設置配置的php.ini {} CLI

例的php.ini:

; Note: This directive is hardcoded to On for the CLI SAPI 

register_argc_argv = On