1. Go to this page and download the library: Download cycle/active-record 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/ */
cycle / active-record example snippets
declare(strict_types=1);
namespace App\Application;
use Spiral\Cycle\Bootloader as CycleBridge;
use Cycle\ActiveRecord\Bridge\Spiral\Bootloader\ActiveRecordBootloader;
class Kernel extends \Spiral\Framework\Kernel
{
public function defineBootloaders(): array
{
return [
// ...
// ORM
CycleBridge\SchemaBootloader::class,
CycleBridge\CycleOrmBootloader::class,
CycleBridge\AnnotatedBootloader::class,
// ActiveRecord
ActiveRecordBootloader::class,
// ...
];
}
use Cycle\ActiveRecord\ActiveRecord;
use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
#[Entity(table: 'users')]
class User extends ActiveRecord
{
#[Column(type: 'primary', typecast: 'int')]
public ?int $id = null;
#[Column(type: 'string')]
public string $name;
public function create(string $name)
{
return self::make([
'name' => $name,
]);
}
}