2010-11-18 35 views
0

我想弄清楚如何为ZF中的模块生成模型?我的逻辑可能有缺陷,但这里是设置:如何在ZF和Doctrine中生成模块模型?

我有一个模块的ZF结构设置。我有一个博客模块和一个游戏模块。我希望这两个系统彼此独立,但共享相同的通用模块,例如用户帐户,它们将托管在单独的数据库IE a Blog DatabaseGame DatabaseCore database之下。所以,我的结构看起来像:

ZF/
- applications/
    - configs 
    - controllers 
    - models 
     User.php 
    - modules 
    - blog 
     - controllers 
     - models 
      Blog.php 
     - views 
    - games 
     - controllers 
     - models 
      Games.php 
     - views 
    - views 

我对你怎么能得到学说产生了各个模块的模型只是有点困惑。我可能会看到这完全错误的,如果任何人都可以摆脱一些见解,我会完全赞赏它,缺乏手动做到这一点。回到尝试做一些更多的研究,看看我能否找到解决方案。

谢谢。

回答

1

AFAIK你不能用你的方式生成它:(对不起, 我之前遇到过同样的问题,我认为最好的解决方案是从应用程序文件夹中生成模型并将它们放入库文件夹,因此结构将是

ZF/
- applications/
    - configs 
    - controllers 
    - models 
    - modules 
    - blog 
     - controllers 
     - models 
     - views 
    - games 
     - controllers 
     - models 
     - views 
    - views 
-library/ 
    -your_custom_namespace 
     -Model 
      User.php 
      Blog.php 
      Games.php 

所以所有的模型也有同样的前缀+节省手动编辑每个生成的模型以适应其命名空间的时间和痛苦。

向下跌破了我的教训cli

<?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/site/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'   =>'site', 
    'phpDocSubpackage'  =>'Models', 
    'phpDocName'   =>'Your Name Goes here', 
    'phpDocEmail'   =>'Your Email', 
    '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 "/../library/Dagho/Model" , 
    'packagesFolderName' => 'packages', 

); 

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

感谢你的这种想法。在我完全放弃自己定制的“Doctrine_Cli”之前,我还有其他一些想法。但谢谢你为我确认这一点。欣赏它。 – 2010-11-19 00:29:59