我用学说构建了zend app。
问题是当我向数据库添加新表时我应该生成doctrine模型,因为我将自己的代码添加到Doctine生成的类中,我不想删除它们。 我解决了这个问题:
我认为我的解决方案可以改进。
答案 0 :(得分:3)
只有基类已经存在才会被覆盖。
不要修改它们。将您的自定义代码放在扩展基类的模型中,这样您的代码将在下一代模型生成时保持不变。
您也可以查看服务层,作为分离模型图层的方法。
还有一条建议:如果你一遍又一遍地重复同样的事情,最好自动化这个,例如。使用Phing。
答案 1 :(得分: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' =>'-----@-----.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']);
?>