I come from a .net background so the empty classes (models) that I'm seeing in Lithium is unsettling.
In .net, I don't have a property unless I do something like:

public class MyClass()
   public property myProp as string
end class

and then I set or get the property like so:

dim aClass as myClass
aClass.myProp = "some string"
dim myString as String = aClass.myProp

What I'm seeing in Lithium are dynamic objects a la javascript.
I can declare an arbitrary object and add properties as I go. Now, I'm not saying this is a bad thing, I just want to know:

  1. If this is normal for PHP or normal for Lithium, and
  2. If I add properties (so I can get code completion in eclipse), will it hurt the ORM features of Lithium?
有帮助吗?

解决方案

Lithium is fairly advanced and takes advantage of some PHP features that many frameworks do not. You can add properties directly to objects in PHP, but, when using a framework, you want to look at what the best practices are and how it will impact your application.

In Lithium, MyModel::create() or MyModel::find() return entity objects or collections of entity objects that represent database records or documents.

Entity properties are stored in the protected $_updated and $_data arrays and accessed via __get and __set methods.

So, when you reference $myModel->title, you're getting/setting $myModel->_updated['title'].

Then, when you call $myModel->save(), the data in $_updated is saved to the database record or document.

See https://github.com/UnionOfRAD/lithium/blob/master/data/Entity.php for more details.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top