2014-02-25 112 views
0

我有以下机制如何描述添加到Doctrine_Record类

CustBillingEmployee: 
    connection: doctrine 
    tableName: cust_billing_employee 
    columns: 
    employee_num: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: false 
    job_title_code: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    cost: 
     type: 'decimal(5, 2)' 
     fixed: false 
     unsigned: false 
     primary: false 
     default: '0.00' 
     notnull: true 
     autoincrement: false 
    relations: 
    HsHrEmployee: 
     local: employee_num 
     foreign: emp_number 
     type: one 

描述表CustBillingEmployee及以下

class cust_billing_employee extends Doctrine_Record 
{ 
    public function setTableDefinition() 
    { 
     $this->hasColumn('employee_num', 'integer',4,array(
     'type' => 'integer', 
     'length' => 4, 
     'fixed' => false, 
     'unsigned' => false, 
     'primary' => true, 
     'autoincrement' => false, 
     )); 
     $this->hasColumn('job_title_code', 'integer',4,array(
     'type' => 'integer', 
     'length' => 4, 
     'fixed' => false, 
     'unsigned' => false, 
     'primary' => false, 
     'notnull' => true, 
     'autoincrement' => false, 
     )); 
     $this->hasColumn('cost', 'decimal',5,array(
      'fixed' => false, 
      'unsigned' => false, 
      'primary' => false, 
      'default' => '0.00', 
      'notnull' => true, 
      'autoincrement' => false, 
     )); 
    } 

    public function setUp() 
    { 
     $this->hasOne('User', array(
      'local' => 'employee_num', 
      'foreign' => 'emp_number' 
     )); 
    } 

    public function __toString() { 
     return "HI"; 
    } 
} 

类当我尝试提取特定的对象,像这样:

echo Doctrine::getTable('CustBillingEmployee')->find(1); 

我得到一个错误

No description for object of class "CustBillingEmployee" 

我希望函数__toString()被父类覆盖,但事实并非如此。那么我应该如何向对象添加一个描述?

当显示我希望能够以显示员工姓名的每个记录,而不是仅仅employee_num键和职位,而不是job_title_cost的

回答

0

你能张贴整个调用堆栈,什么样的代码抛出错误?

对我来说有什么可疑的是cust_billing_employee这个类别的名称不是CustBillingEmployee而是不会延伸BaseCustBillingEmployee这将是Symfony 1.4的默认行为。你是否亲手写了这段代码?

由于您的模式是在schema.yml中定义的,因此您应该使用./symfony doctrine:build-model任务。

这应该会生成正确的类别:CustBillingEmployee延伸BaseCustBillingEmployee其中延伸sfDoctrineRecord,然后Doctrine_Core::getTable('CustBillingEmployee')->find(1)应该完美工作。

另外请注意,你不应该触摸BaseCustBillingEmployee,因为这是为了自动生成代码,所有修改(如__toString)应该在CustBillingEmployee类中完成。