1. Go to this page and download the library: Download muffin/sti library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
muffin / sti example snippets
// src/Model/Table/CooksTable.php
namespace App\Model\Table;
use Cake\ORM\Table;
class CooksTable extends Table
{
public function initialize($config)
{
$this->setTable('sti_cooks');
$this->addBehavior('Muffin/Sti.Sti', [
'typeMap' => [
'chef' => 'App\Model\Entity\Chef',
'baker' => 'App\Model\Entity\Baker',
'assistant_chef' => 'App\Model\Entity\AssistantChef',
]
]);
// Optionally, set the default type. If none is defined, the
// first one (i.e. `chef`) will be used.
$this->setEntityClass('App\Model\Entity\AssistantChef');
}
}
// src/Model/Entity/AssistantChef.php
namespace App\Model\Entity;
use Cake\ORM\Entity;
use Muffin\Sti\Model\Entity\StiAwareTrait;
class AssistantChef extends Entity
{
use StiAwareTrait;
}
// src/Model/Table/CooksTable.php
public function validationChefs(Validator $validator)
{
// ...
return $validator;
}
// using the parent table
$cooks->newChef([...]);
// or, using the parent table again
$cooks->newEntity(['type' => 'chef', ...]);
// or, using the child table
$chefs->newEntity([...]);