Reputation: 28050
I am using cakephp 3.1
Suppose I have this simple controller action below.
public function apiGetAccessKey($username)
{
$query = $this->Customers
->find()
->select('access_key')
->where(['username' => $username]);
}
I want to transfer it into the Model since it involves data extraction. With cakephp 3.x, model is divided into Table and Entity. Which should I use? Table or Entity? How should the code look like?
Upvotes: 0
Views: 225
Reputation: 25698
Entities represent data, table objects access and process data.
Like I already recommended you in the other question I'll do it again: Read the manual. You approach of "trial and error and then ask" is not very effective. Read the book, try the code examples. If something remains unclear finally ask about that.
This is taken directly from the book:
Table objects provide access to the collection of entities stored in a specific table. Each table in your application should have an associated Table class which is used to interact with a given table.
While Table Objects represent and provide access to a collection of objects, entities represent individual rows or domain objects in your application. Entities contain persistent properties and methods to manipulate and access the data they contain.
Upvotes: 1