Question

In lithium, document and record classes, or their superclasses/interfaces, have no save() method. Yet lithium's method for saving the record is as follows:

$record = Model::create()
$record->save()

I am not certain how this works, since record does not have save method (only Model has).

Was it helpful?

Solution

Document and Record extend from a base Entity class. The Entity class has a __call() magic method. See the api doc for Entity::__call over here: http://li3.me/docs/lithium/data/Entity::__call() That method obtains an instance of the Model class associated with the Entity and then calls the method passing the entity object in as the first argument. The Adding Functions To Models section of the Lithium manual also contains additional info related to this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top