English 中文(简体)
What does mutators and accessors do in Doctrine?
原标题:
  • 时间:2009-11-27 06:47:46
  •  标签:
  • doctrine

In this document, it explains how to use mutators and accessors in Doctrine, but does not explain what they are.

Could anyone explain what mutators and accessors do and what they are?

Thanks in advance.

最佳回答

You can use mutators and accessors to implement additional behavior for your models fields. Basically they transform the value from one form into another. For example if you look at Doctrine s docs they specify a md5Password mutator. Mutator means that Doctrine will call the specified mutator method whenever you set the value for the field. So whenever you do:

$user->password =  foobar ;

Doctrine will call the md5Password() of the model, hence transforming foobar into md5( foobar ). In a nutshell this ensures that the password is always hashed on software-level.

Accessor is the opposite of mutator; it ll be called when the field is being read instead of being set (eg. when a row is read from the database).

问题回答

暂无回答




相关问题
Doctrine quoting apostrophes

I am using Doctrine ORM for php and Zend MVC. I have a mysql database. When I insert into the database it is escaping quotes. In other-words when I enter <input name="customer_name" value="Test ...

What does mutators and accessors do in Doctrine?

In this document, it explains how to use mutators and accessors in Doctrine, but does not explain what they are. Could anyone explain what mutators and accessors do and what they are? Thanks in ...

Tracking the views of a given row

I have a site where the users can view quite a large number of posts. Every time this is done I run a query similar to UPDATE table SET views=views+1 WHERE id = ?. However, there are a number of ...

Doctrine schema.yml generator

I am pretty new to doctrine. I made two small projects with doctrine for my own but now I am about to create big project for my client. The project will have more than 50 tables. Is there any way of ...

How does Doctrine handle changes to the database schema?

In brief, what happens when you add a column to a table? What happens when you remove one? In more details, suppose you have the following: class User extends Doctrine_Record { public function ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签