开发者

Zend Framework, Doctrine Help needed

I am following the tutorial from Introducing Doctrine 1.2 Integration

I have a doctrine.php that "bootstraps?" doctrine ... sorry I don't really fully understand the tutorial yet.

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/..'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);

$application->getBootstrap()->bootstrap('doctrine');
$config = $application->getOption('doctrine');

$cli = new Doctrine_Cli($config);
$cli->run($_SERVER['argv']);

when I try to run it via cmd,

php.exe doctrine.php

I got

D:\Projects\ZF\doctrine\application\scripts>php -f doctrine.php
PHP Fatal error:  Uncaught exception 'LogicException' with message 'Passed array does not specify an existing static met
hod (class 'Doctrine' not found)' in D:\Projects\ZF\doctrine\application\Bootstrap.php:7
Stack trace:
#0 D:\Projects\ZF\doctrine\application\Bootstrap.php(7): spl_autoload_register(Array)
#1 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Application\Bootstrap\BootstrapAbstract.php(662): Bootstrap-
>_initDoctrine()
#2 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Application\Bootstrap\BootstrapAbstract.php(622): Zend_Appli
cation_Bootstrap_BootstrapAbstract->_executeResource('doctrine')
#3 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Application\Bootstrap\BootstrapAbstract.php(579): Zend_Appli
cation_Bootstrap_BootstrapAbstract->_bootstrap('doctrine')
#4 D:\Projects\ZF\doctrine\application\scripts\doctrine.php(25): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap
('doctrine')
#5 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Loader.php(136): include('D:\Projects\ZF in D:\Projects\ZF\d
octrine\application\Bootstrap.php on line 0

Update 1

protected function _initDoctrine() {
    $this->getApplication()->getAutoloader()
         ->pushAutoloader(array('Doctrine', 'autoload'));
    spl_autoload_register(array('Doctrine', 'modelsAutoload'));

    $manager = Doctrine_Manager::getInstance();
    $manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
    $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
    $manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);

    $doctrineConfig = $this->getOption("doctrine");
    $conn = Doctrine_Manager::connection($doctrineConfig['dsn']);
    $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
    return $conn;
}

under sql\_autoload\_register() I guess. I don't really get what spl\_autoload\_register() also ... even in php reference.

Update 2

my bootstrap.php

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
    protected function _initDoctrine() {
        $this->getApplication()->getAutoloader()
                ->pushAutoloader(array('Doctrine', 'autoload'));
        spl_autoload_register(array('Doctrine', 'modelsAutoload'));

        $manager = Doctrine_Manager::getInstance();
        $manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
        $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
        $manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);

        $doctrineConfig = $this->getOption("doctrine");
        Doctrine::loadModels($doctrineConfig['models_path']);

        $conn = Doctrine_Manager::connection($doctrineConfig['dsn'], 'Doctrine');
        $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
        return $conn;
    }
}

I guess the thing thats not working is Zend does not seem to autoload the Doctrine class. which its supposed to because I already have registered the Doctrine namespace in config.ini

autoloaderNamespaces[] = "Doctrine"

Does this mean Zend shld autoload Doctrine classes?

as for where Doctrine is stored, i have pointed to it inside PHP's include path.

开发者_运维问答

include_path = ".;c:\php\includes;D:\ResourceLibrary\Frameworks\ZendFramework\library;D:\ResourceLibrary\Frameworks\Doctrine121sandbox\lib"

I noted that if in _initDoctrine(), I require Doctrine manually it works.

require_once 'D:\ResourceLibrary\Frameworks\Doctrine121sandbox\lib\Doctrine.php';

has it got something to do with windows path (\ as separator)


Do you have the rest of the Zend Framework stuff working without the use of Doctrine? If so, you have a bootstrap file that you use for that application. Assuming a default directory layout, if you have your doctrine.php in your scripts directory and your bootstrap.php in your application directory, you should be able to just do this to get your doctrine cli working in doctrine.php:

require dirname(__FILE__).'/../application/global.php';
// the config line below might be different based on how you have your
// doctrine config stuff set up
$cli = new Doctrine_Cli(Zend_Registry::get('doctrine_config'));
$cli->run($_SERVER['argv']);

In your bootstrap.php (or a file required by your bootstrap.php), your autoloader should be configured something like this:

// set up your include path here
set_include_path(dirname(__FILE__).'/../library/zendframework'
. PATH_SEPARATOR . dirname(__FILE__).'/../library/doctrine'
. PATH_SEPARATOR . dirname(__FILE__).'/models'
. PATH_SEPARATOR . dirname(__FILE__).'/models/generated'
. PATH_SEPARATOR . dirname(__FILE__).'/business'
. PATH_SEPARATOR . dirname(__FILE__).'/business/exceptions'
. PATH_SEPARATOR . dirname(__FILE__).'/business/util'
. PATH_SEPARATOR . dirname(__FILE__).'/business/validators'
. PATH_SEPARATOR . get_include_path());
require 'Zend/Loader/Autoloader.php';

$loader = Zend_Loader_Autoloader::getInstance();
$loader->suppressNotFoundWarnings(false);
$loader->setFallbackAutoloader(true);

Post here if this doesn't work. We had a bunch of issues setting this up in the beginning with Zend Framework's autoloader.


I did face the same problem and got over it successfully what you need to do is change this

    $manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);

to

    $manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, false);

and i did remove this line also

  spl_autoload_register(array('Doctrine', 'modelsAutoload'));

I had reported these errors in the same zendcasts forums
these steps helped me to work with doctrine as expected :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜