2010-05-16 18 views
0

我构建与教条的zend应用程序。如何生成新的学说模型没有删除教条模型类与我的代码添加

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

  1. 复制旧产生doctine模型类到其他文件夹
  2. 生成数据库理论模型
  3. 删除与旧

我认为同样的新学说机型类我的解决方案可以改进。

回答

3

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

不要修改它们。将您的自定义代码放入扩展基类的模型中,以便您的代码在下一代模型生成时保持不变。

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

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

0

这里是我的教训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'   =>'[email protected]', 
    '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']); 
?> 
相关问题