Download the PHP package muffin/sti without Composer
On this page you can find all versions of the php package muffin/sti. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package sti
Short Description Single Table Inheritance for CakePHP ORM
License MIT
Homepage https://github.com/usemuffin/sti
Informations about the package sti
Sti
Single Table Inheritance for CakePHP ORM.
[...] a way to emulate object-oriented inheritance in a relational database. When mapping from a database table to an object in an object-oriented language, a field in the database identifies what class in the hierarchy the object belongs to.
(source: Wikipedia)
Install
Using Composer:
You then need to load the plugin. You can use the console command:
Usage
Then create a class for every type of entity:
- Chef
- Baker
- AssistantChef
The entity that was previously defined to be the 'default' one will need to use the StiAwareTrait
:
Optionally, you can create classes for your tables that extend the parent table to encapsulate business logic:
I said optionally, because if the only thing you need is some extra validation rules, you could define those on the parent table. For example, to add custom rules to chefs:
New entities
The behavior will automatically add helper methods for creating entities of different types
(i.e. newChef()
). There are different ways of creating new entities, all are valid and depending
on the cases, you might need one or the other:
Note
For the above examples to work using (*chef), you need to add a custom rule to the Inflector
:
Patches & Features
- Fork
- Mod, fix
- Test - this is important, so it's not unintentionally broken
- Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of their own that I can ignore when I pull)
- Pull request - bonus point for topic branches
To ensure your PRs are considered for upstream, you MUST follow the CakePHP coding standards.
Bugs & Feedback
http://github.com/usemuffin/sti/issues
License
Copyright (c) 2015-Present, Use Muffin and licensed under The MIT License.