Download the PHP package ronanchilvers/orm without Composer

On this page you can find all versions of the php package ronanchilvers/orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package orm

ronanchilvers/orm

Actions Status Scrutinizer Code Quality

orm is a small and simple database layer implementing the active record pattern. Its aim is to be simple, fast and useful. It relies on the [clancats hydrahon] query builder for database query access.

Overview

Things it does

Things it does NOT do

Installation

You'll need at least PHP7.0 to use the library. The recommended way to install is using composer:

Configuring the database

Since orm uses PDO, it's up to you how you create and instantiate your PDO object. This will probably be in your bootstrap somewhere. Once your PDO object is available you will need to give it to orm. Here's an example:

Clearly you will almost certainly not be using a :memory: DSN in practice. However you create your PDO object, the crucial point here is that you call Orm::setConnection to provide orm with your connection object.

Basic usage

orm doesn't make any pre-judgments about your database schema. When building models from a database it assumes it maps columns to properties and when saving it assumes that any property has a corresponding database table column. Its up to you to make sure the data makes sense.

Here we assume that we have a database table that looks like the following. We're using MySQL / MariaDB syntax here but whatever PDO supports should be fine.

Defining a model

First create your model class. It should extend the Ronanchilvers\Orm\Model class. As with many active record implementations we assume here that the table has a plural name (books) and its corresponding model class will have a singular name (book).

If your columns have no column prefix, that's all you need to do. The table name will be inferred from the class name. If however, like the example above, you have column prefixes then you can tweak your model to suit.

Similarly if your table doesn't map to the model name you can specufy that too.

Now you're ready to use the model.

Finding models

orm supports a query builder interface provided by clancats/hydrahon. In order to retrieve models from the database, first obtain a finder object.

Then you can use the finder object to retrieve models.

There are several standard finder methods you can use:

You can use the full query builder to gain more control over the query:

You can read more about the capabilities of the query builder over at the clancats/hydrahon site.

If you want complete control over the SQL that is executed you can do:

Custom Finder Classes

By default Orm::finder will give you back a vanilla Ronanchilvers\Orm\Finder object tied to given model class. However you can also override the finder class for a given model by setting the $finder static property on your model. This can be very useful if you want to add custom find methods (for example).

Let's imagine you've created a BookFinder class:

You can see that we've created a subclass of the default finder and we've added a forAuthorId method which returns an array of books for a given author id.

Then we tell the model about our new finder class:

and then finally you're readdy to use it:

Persistence

Saving a model back to the database is simply a matter of calling the save method.

Similarly destroying a model is also simple:

Accessing model data

As in any active record implementation, database table columns are expressed as properties on the model instance. Consequently data can be accessed by accessing those properties.


All versions of orm with dependencies

PHP Build Version
Package Version
Requires clancats/hydrahon Version ^1.1
evenement/evenement Version ^3.0
nesbot/carbon Version ^2.0
php Version ^8.0
ronanchilvers/utility Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ronanchilvers/orm contains the following files

Loading the files please wait ....