Là một dự án mã nguồn mở, cakephp/orm đã đạt 149 sao trên GitHub, ngôn ngữ PHP. [READ-ONLY] A flexible, lightweight and powerful Object-Relational Mapper for PHP, implemented using the DataMapper pattern. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
The CakePHP ORM provides a powerful and flexible way to work with relational
databases. Using a datamapper pattern the ORM allows you to manipulate data as
entities allowing you to create expressive domain layers in your applications.
Database engines supported
The CakePHP ORM is compatible with:
MySQL 5.1+
Postgres 8+
SQLite3
SQLServer 2008+
Oracle (through a community plugin)
Connecting to the Database
The first thing you need to do when using this library is register a connection
object. Before performing any operations with the connection, you need to
specify a driver to use:
Once a 'default' connection is registered, it will be used by all the Table
mappers if no explicit connection is defined.
Using Table Locator
In order to access table instances you need to use a Table Locator.
use Cake\ORM\Locator\TableLocator;
$locator = new TableLocator();
$articles = $locator->get('Articles');
You can also use a trait for easy access to the locator instance:
use Cake\ORM\Locator\LocatorAwareTrait;
$articles = $this->getTableLocator()->get('Articles');
By default, classes using LocatorAwareTrait will share a global locator instance.
You can inject your own locator instance into the object:
use Cake\ORM\Locator\TableLocator;
use Cake\ORM\Locator\LocatorAwareTrait;
$locator = new TableLocator();
$this->setTableLocator($locator);
$articles = $this->getTableLocator()->get('Articles');
Creating Associations
In your table classes you can define the relations between your tables. CakePHP's ORM
supports 4 association types out of the box:
belongsTo - E.g. Many articles belong to a user.
hasOne - E.g. A user has one profile.
hasMany - E.g. A user has many articles.
belongsToMany - E.g. An article belongsToMany tags.
You define associations in your table's initialize() method. See the
documentation for
complete examples.
Reading Data
Once you've defined some table classes you can read existing data in your tables:
use Cake\ORM\Locator\LocatorAwareTrait;
$articles = $this->getTableLocator()->get('Articles');
foreach ($articles->find() as $article) {
echo $article->title;
}
You can use the query builder to create
complex queries, and a variety of methods
to access your data.
Saving Data
Table objects provide ways to convert request data into entities, and then persist
those entities to the database:
The above shows how you can easily marshal and save an entity and its
associations in a simple & powerful way. Consult the ORM documentation
for more in-depth examples.
Deleting Data
Once you have a reference to an entity, you can use it to delete data:
It is recommended to enable metadata cache for production systems to avoid performance issues.
For e.g. file system strategy your bootstrap file could look like this:
Cache configs are optional, so you must require cachephp/cache to add one.
Creating Custom Table and Entity Classes
By default, the Cake ORM uses the \Cake\ORM\Table and \Cake\ORM\Entity classes to
interact with the database. While using the default classes makes sense for
quick scripts and small applications, you will often want to use your own
classes for adding your custom logic.
When using the ORM as a standalone package, you are free to choose where to
store these classes. For example, you could use the Data folder for this:
<?php
// in src/Data/Table/ArticlesTable.php
namespace Acme\Data\Table;
use Acme\Data\Entity\Article;
use Acme\Data\Table\UsersTable;
use Cake\ORM\Table;
class ArticlesTable extends Table
{
public function initialize()
{
$this->setEntityClass(Article::class);
$this->belongsTo('Users', ['className' => UsersTable::class]);
}
}
This table class is now setup to connect to the articles table in your
database and return instances of Article when fetching results. In order to
get an instance of this class, as shown before, you can use the TableLocator:
<?php
use Acme\Data\Table\ArticlesTable;
use Cake\ORM\Locator\TableLocator;
$locator = new TableLocator();
$articles = $locator->get('Articles', ['className' => ArticlesTable::class]);
Using Conventions-Based Loading
It may get quite tedious having to specify each time the class name to load. So
the Cake ORM can do most of the work for you if you give it some configuration.
The convention is to have all ORM related classes inside the src/Model folder,
that is the Model sub-namespace for your app. So you will usually have the
src/Model/Table and src/Model/Entity folders in your project. But first, we
need to inform Cake of the namespace your application lives in:
<?php
use Cake\Core\Configure;
Configure::write('App.namespace', 'Acme');
You can also set a longer namaspace up to the place where the Model folder is:
<?php
use Cake\Core\Configure;
Configure::write('App.namespace', 'My\Log\SubNamespace');
Additional Documentation
Consult the CakePHP ORM documentation
for more in-depth documentation.
cakephp/orm có 149 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/cakephp/orm. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
cakephp/orm có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho cakephp/orm. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
cakephp/orm có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho cakephp/orm. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
cakephp/orm có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho cakephp/orm. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
cakephp/orm còn đang phát triển không?
Commit gần nhất trên cakephp/orm là 9 ngày trước (theo timestamp GitHub). Repo có 14 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc thêm về cakephp/orm ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/cakephp/orm là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về orm?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về orm.