开发者

Can't change model builder options

I'm trying to get symfony to use a custom class called jsDoctrineRecord instead of sfDoctrineRecord for its models. Here's the code for the overriding class:

<?php
abstract class jsDoctrineRecord extends sfDoctrineRecord
{
  public function foo()
  {
    echo 'foo';exit;
  }
}

Here's what I have in config/ProjectConfiguration.class.php, per the instructions here:

<?php

require_once dirname(__FILE__).'/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::register();

class ProjectConfiguration extends sfProjectConfiguration
{
  public fu开发者_如何学JAVAnction setup()
  {
    $this->enablePlugins('sfDoctrinePlugin');
    $this->enablePlugins('sfDoctrineGuardPlugin');
    $this->enablePlugins('jsDoctrineSchemaOverriderPlugin');
  }

  public function configureDoctrine(Doctrine_Manager $manager)
  {
    $options = array('baseClassName' => 'jsDoctrineRecord');
    sfConfig::set('doctrine_model_builder_options', $options);
  }
}

Unfortunately, this doesn't work. My models continue to inherit from sfDoctrineRecord instead of jsDoctrineRecord. The foo() method is not recognized. I still have the problem when I clear my cache.

I'm pretty sure I'm following the instructions right, so what could be going wrong?


Im not sure whay thats not working as its still there for BC, but after looking at the sfDoctrinePlugin it looks like the proper way to handle this is with a symfony event listener (see lines 83 - 89 of SF_LIB_DIR/plugins/sfDoctrinePlugin/config/sfDoctrinePluginConfiguration.class.php):

in projectConfiguration:

public function setup()
{
   $this->enablePlugins('sfDoctrinePlugin');
   $this->enablePlugins('sfDoctrineGuardPlugin');
   $this->enablePlugins('jsDoctrineSchemaOverriderPlugin');

   $this->dispatcher->connect(
     'doctrine.filter_model_builder_options', 
     array($this, 'configureDoctrineBuildOptions')
   );
}

public function configureDoctrineBuildOptions(sfEvent $event, $options)
{
   $options['baseClassName'] = 'jsDoctrineRecord';

   return $options;
}

Give that a shot and see if it makes a difference.


You need to rebuild the model so that the Base record classes extend your new record class. Run doctrine:build-model.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜