【问题标题】:Adding property by hand to Base model in Symfony1.4 and Doctrine在 Symfony 1.4 和 Doctrine 中手动向 Base 模型添加属性
【发布时间】:2014-02-09 14:43:49
【问题描述】:

我在表Empresa 中添加了一个新字段,所以我需要更改我的模型。为了不重新生成意味着模型表单过滤器的全部内容,我决定手动(手动)添加它,所以我尝试将属性添加到BaseSdrivingEmpresa.class.php,如下所示:

<?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 |内部服务器错误 | 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() ?>

我的错误在哪里?

【问题讨论】:

    标签: php doctrine symfony1 symfony-1.4 doctrine-1.2


    【解决方案1】:

    首先,手动编辑您的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
    

    这将在不触及您提到的表单、过滤器的情况下重建您的模型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多