代码之家  ›  专栏  ›  技术社区  ›  Jeremy Hicks

Zend框架与学说的整合问题

  •  1
  • Jeremy Hicks  · 技术社区  · 15 年前

    我以前在另一台机器上做过这个,而且设置几乎是相同的。然而,它只是不在新机器上工作。当我试图让学说产生我的模型时,它把它们放错了地方。它为基类和常规类创建了一个额外的“model”目录。我用的是ZF 1.11.0中的条令1.2.3。这是我的zf application.ini:

    [production]
    phpSettings.display_startup_errors = 0
    phpSettings.display_errors = 0
    phpSettings.date.timezone = "America/Denver"
    includePaths.library = APPLICATION_PATH "/../library"
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
    appnamespace = ""
    
    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
    resources.frontController.params.displayExceptions = 0
    resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
    resources.view[] = 
    
    autoloaderNamespaces[] = "Doctrine_"
    autoloaderNamespaces[] = "App_"
    
    doctrine.connection_string = "mysql://root@localhost/mydb"
    ;doctrine.cache = true
    
    doctrine.data_fixtures_path = APPLICATION_PATH "/doctrine/data/fixtures"
    doctrine.sql_path = APPLICATION_PATH "/doctrine/data/sql"
    doctrine.migrations_path = APPLICATION_PATH "/doctrine/migrations"
    doctrine.yaml_schema_path = APPLICATION_PATH "/doctrine/schema"
    doctrine.models_path = APPLICATION_PATH "/models"
    
    doctrine.generate_models_options.pearStyle = true
    doctrine.generate_models_options.generateTableClasses = true
    doctrine.generate_models_options.generateBaseClasses = true
    doctrine.generate_models_options.baseClassPrefix = "Base_"
    doctrine.generate_models_options.baseClassesDirectory =
    doctrine.generate_models_options.classPrefixFiles = false
    doctrine.generate_models_options.classPrefix = "Model_"
    
    [staging : production]
    
    [testing : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1
    
    [development : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1
    resources.frontController.params.displayExceptions = 1
    

    以下是我的zf bootstrap.php文件中的条令函数:

    protected function _initDoctrine()
    {
        $this->getApplication()->
            getAutoloader()->
            pushAutoloader(array('Doctrine_Core', 'autoload'));
    
        $config = $this->getOption('doctrine');
    
        $manager = Doctrine_Manager::getInstance();
        $manager->setAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX, 'Model_');
        $manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_PEAR);
        $manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
        $manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);
        $manager->setAttribute(Doctrine_Core::ATTR_AUTO_FREE_QUERY_OBJECTS, true);
        $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
        $manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
    
        if (isset($config['cache']) && $config['cache'] == true) {
            $cacheDriver = new Doctrine_Cache_Apc();
            $manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
        }
    
        $connection = $manager->openConnection($config['connection_string'], 'doctrine');
        $connection->setAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM, true);
        $connection->setCharset('utf8');
    
        return $connection;
    }
    

    下面是我的doctrine.php命令行脚本:

    // Define path to application directory
    defined('APPLICATION_PATH')
        || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
    
    // 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']);
    

    所以,我希望我的模型目录最终是这样的:

    models
      Base
        -Class1.php
        -Class2.php
      -Class1.php
      -Class1Table.php
      -Class2.php
      -Class2Table.php
    

    其中,基类名的格式与model_base_class1类似,常规类名是model_class1(在实际的PHP文件中)。相反,我得到的是:

    models   
      Base
        Model
          -Class1.php
          -Class2.php   Model
        -Class1.php
        -Class1Table.php
    

    看到额外的模型目录了吗?这是什么原因造成的?我试过在in i中处理district.generate_models_options.class prefix选项,以及bootstrap.php文件中的类似设置$manager->setattribute(distrine_core::attr_model_class_prefix,'model');

    请帮帮我!

    1 回复  |  直到 15 年前
        1
  •  1
  •   Jeremy Hicks    15 年前

    嗯,我又不是那么聪明了。:(只是我的schema.yaml文件配置错误。我把model_user作为模型名,而不仅仅是user!但是,fixtures文件要求它是model_用户。问题解决了。