Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are entity classes in php [closed]

Tags:

php

entity

I'm currently learning MVC as it pertains to php and I came across something called an entity class, but cannot for the life of me find a clear explanation and/or an example of it.

I thought it was a class that held the data from a database that the model retrieved and is then passed to a view, but i have this nagging feeling that I'm way off.

Can someone please explain it via an example or point me in the right direction?

like image 979
zero Avatar asked Dec 04 '12 20:12

zero


People also ask

What are entities in PHP?

Entities are usually objects defined by classes with variables that store values of simple objects that represent important application data structures. This package provides an implementation of simple classes that can be used define entity objects that can provide their own consistency checking methods.

What are the entity classes?

An entity class is essentially an object wrapper for a database table. The attributes of an entity are transformed to columns on the database table.

Why do we use entity classes?

Some reasons for using entities are: When the key is a property of an entity object representing the record as a whole, the object's identity and concept are often clearer than with key and value objects that are disjoint. A single entity object per record is often more convenient to use than two objects.

What is an entity class example?

Example of entity classes are: computer, department and company. All computers in the company share attributes, all departments share attributes and all companies share attributes. An entity is an instance of an entity class.


1 Answers

To expand on the comments above:

Your application models a real-world scenario, which will include a number of entities. The example entity you give is an Administrator; this entity likely inherits properties from a more general User entity.

Entity classes, then, are simply classes that represent your real-world entities:

class User {}
class Administrator extends User {}

An entity class only differs from a normal class in its semantic significance; a Controller class would probably not be an entity class, as it's part of the application framework rather than representing a real-world concept.

How your entity classes interact will likely be closely related to how your actual entities interact, so the relationships between entity classes (inheritance/association) will mirror your Entity Relationship Diagram.

like image 113
cmbuckley Avatar answered Sep 25 '22 11:09

cmbuckley