【问题标题】:How generate new doctrine models without delete doctrine models classes with my code addition如何通过我的代码添加生成新的学说模型而不删除学说模型类
【发布时间】:2010-05-16 21:14:20
【问题描述】:

我用学说构建 zend 应用程序。

问题是当我向数据库添加新表并且我应该生成学说模型时,因为我将自己的代码添加到 Doctine 生成的类中,我不想删除它们。 我这样解决这个问题:

  1. 将旧生成的 doctine 模型类复制到其他文件夹
  2. 从数据库生成理论模型
  3. 删除与旧的相同的新学说模型类

我认为我的解决方案可以改进。

【问题讨论】:

    标签: zend-framework doctrine


    【解决方案1】:

    只有基类已经存在时才会被覆盖。

    不要修改它们。将您的自定义代码放在扩展基类的模型中,这样您的代码将在下一代模型中保持不变。

    您也可以查看服务层,作为分离模型层的方法。

    还有一个建议:如果你一遍又一遍地重复同样的事情,最好自动化这个,例如。使用Phing

    【讨论】:

      【解决方案2】:

      这是我的学说 CLI 的主要思想

         'generateBaseClasses'   => true,
         'generateTableClasses'  => false,
      

      那里的学说cli只会重新创建基类,你会保存你的工作

      干杯

      tawfek daghistani

      <?php
      echo "Hello Tawfek ! , Howdy ?? \n";
      /**
       * Doctrine CLI
       */
      error_reporting(E_ALL);
      define('ROOT_PATH', realpath(dirname(__FILE__)));
      define('APPLICATION_PATH', realpath(dirname(__FILE__) . "/../"));
      define('APPLICATION_ENV', 'development');
      //Ensure library/ is on include_path
      set_include_path(implode(PATH_SEPARATOR, array(
          '../library',get_include_path(), "/home/------/Sites/font/library/" )));
      /** Zend_Application */
      require_once 'Zend/Application.php';
      
      // Create application, bootstrap, and run
      $application = new Zend_Application(
          APPLICATION_ENV,
          APPLICATION_PATH . '/configs/application.ini'
      );
      
      // Read in the application.ini bootstrap for Doctrine
      $application->getBootstrap()->bootstrap('doctrine');
      
      // Create the configuration array
      $config = $application->getOption('doctrine');
      // (Note you can have all of these in application.ini aswell)
      $config['generate_models_options'] = array(
          // Define the PHPDoc Block in the generated classes
          'phpDocPackage'         =>'Font',
          'phpDocSubpackage'      =>'Models',
          'phpDocName'            =>'Tawfek Daghistani',
          'phpDocEmail'           =>'-----@-----.com',
          'phpDocVersion'         =>'1.0',
          // Define whats what and named how, where.
          'suffix'                => '.php',
          'pearStyle'             => true,
          'baseClassPrefix'       => 'Base_',
          // Unless you have created a custom class or want Default_Model_Base_Abstract
          'baseClassName'         => 'Doctrine_Record',
          // Leave this empty as specifying 'Base' will create Base/Base
          'baseClassesDirectory'  => NULL,
          // Should make it Zend Framework friendly AFAIK
          'classPrefix'           => 'Dagho_Model_',
          'classPrefixFiles'      => false,
          'generateBaseClasses'   => true,
          'generateTableClasses'  => false,
          'packagesPath'          => APPLICATION_PATH . '/models',
          'packagesFolderName'    => 'packages',
      
      );
      
      $cli = new Doctrine_Cli($config);
      $cli->run($_SERVER['argv']);
      ?>
      

      【讨论】:

        猜你喜欢
        • 2011-06-01
        • 1970-01-01
        • 2013-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-22
        • 2011-05-06
        相关资源
        最近更新 更多