2014-02-09 86 views
0

我在表Empresa中添加了一个新字段,所以我需要更改我的模型。对于无法再生的整个事情意味着模型形式的过滤器我决定用手工(手动)进行添加,所以我试图将属性添加到BaseSdrivingEmpresa.class.php如下:手动添加属性到Symfony1.4和Doctrine的基本模型

<?php 

/** 
* BaseSdrivingEmpresa 
* 
* This class has been auto-generated by the Doctrine ORM Framework 
* 
* @property integer $umbralvoz 
* 
* @method integer     getUmbralvoz()     Returns the current record's "umbralvoz" value 
* @method SdrivingEmpresa   setUmbralvoz()     Sets the current record's "umbralvoz" value 
* 
* @package isecurdriving 
* @subpackage model 
* @author  Your name here 
* @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $ 
*/ 
abstract class BaseSdrivingEmpresa extends sfDoctrineRecord { 

    public function setTableDefinition() { 
     $this->setTableName('sdriving_empresa'); 

     $this->hasColumn('umbralvoz', 'integer', 11, array(
      'type' => 'integer', 
      'notnull' => false, 
      'default' => 60, 
      'length' => 11, 
     )); 
    } 

} 

但我得到这个错误:

500 | Internal Server Error | Doctrine_Record_UnknownPropertyException

任何时候,我尝试获得的财产,以显示它的模板:

$id_empresa = $this->getUser()->getGuardUser()->getSfGuardUserProfile()->getIdempresa(); 
$this->sdriving_configuracion = Doctrine_Core::getTable('SdrivingEmpresa')->createQuery('a')->where('a.idempresa = ?', $id_empresa)->execute(); 

<?php echo $sdriving_configuracion[0]->SdrivingEmpresa->getUmbralvoz() ?> 

哪里是我的错误?

回答

2

首先,您的Base*.class.php的手动编辑不是一个好主意,因为这个类是自动生成的,并且会被下一个模型构建覆盖。如果您想手动执行任何操作,您应该直接在BaseSdrivingEmpresa.class.php的子目录SdrivingEmpresa.class.php。 第二件事情是,这种修改更好的地方是SdrivingEmpresaTable.class.php。所以看起来我会建议修改getInstance方法:

public static function getInstance() 
{ 
    $this->setColumn('umbralvoz', 'integer', 11, array(
     'type' => 'integer', 
     'notnull' => false, 
     'default' => 60, 
     'length' => 11, 
    )); 
    return Doctrine_Core::getTable('SdrivingEmpresa'); 
} 

最后,我认为,在这种情况下,最好的解决办法只是简单地修改你的schema.yml文件,添加列,然后使用命令

./symfony doctrine:build-model 

这将重建您的模型,而不会触摸您提到的窗体,过滤器。