如何向Doctrine

编程入门 行业动态 更新时间:2024-10-24 10:17:09
如何向Doctrine_Record类添加描述(How to add description to a Doctrine_Record class)

我有一个表CustBillingEmployee在下面的方案中描述

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

以及下面的课程

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

I have a table CustBillingEmployee described in the scheme below

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

and the class below

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"; } }

When I try to extract a particular object like so:

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

I get an error

No description for object of class "CustBillingEmployee"

I was hoping that the function __toString() gets overridden from the parent class but that is not the case. How shall I add a description to the object then?

When displaying each record I want to be able to display employee name instead of just employee_num key and job title instead of job_title_cost

最满意答案

你可以发布整个调用堆栈,什么代码抛出该错误?

对我来说可疑的是cust_billing_employee类的名称不是CustBillingEmployee而不是扩展BaseCustBillingEmployee ,它将是Symfony 1.4的默认行为。 你是否“手工”编写了这段代码?

由于您的架构是在schema.yml中定义的,因此您应该使用./symfony doctrine:build-model task。

这应该生成正确的类: CustBillingEmployee扩展了BaseCustBillingEmployee ,扩展了sfDoctrineRecord ,然后是Doctrine_Core::getTable('CustBillingEmployee')->find(1)应该可以正常工作。

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

Can you post whole call stack, what code throws that error?

What is suspicious to me is the name of the class cust_billing_employee not being CustBillingEmployee and not extending BaseCustBillingEmployee which would be default behaviour of Symfony 1.4. Did you wrote this code 'by hand' ?

Since your schema is defined in schema.yml you should be using ./symfony doctrine:build-model task.

This should generate correct classes: CustBillingEmployee extending BaseCustBillingEmployee which extends sfDoctrineRecord and then Doctrine_Core::getTable('CustBillingEmployee')->find(1) should work perfectly.

Also note, that you should not touch BaseCustBillingEmployee as this is meant to be autogenerated code, all modifications (like __toString) should be done in CustBillingEmployee class.

更多推荐

本文发布于:2023-07-16 13:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1129019.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Doctrine

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!