PHP code example of bigins / imanager

1. Go to this page and download the library: Download bigins/imanager 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/ */

    

bigins / imanager example snippets




use Imanager\DefaultBootstrap;
use Imanager\Domain\Category;
use Imanager\Domain\Field;
use Imanager\Domain\Item;
use Imanager\Enum\FieldType;
use Imanager\Storage\CategoryRepository;
use Imanager\Storage\FieldRepository;
use Imanager\Storage\ItemRepository;

$container = DefaultBootstrap::boot(
    databasePath: __DIR__ . '/data/imanager.db',
    uploadsPath:  __DIR__ . '/data/uploads',
    uploadsUrl:   '/uploads',
    cachePath:    __DIR__ . '/data/cache',
);

$categories = $container->get(CategoryRepository::class);
$fields     = $container->get(FieldRepository::class);
$items      = $container->get(ItemRepository::class);

// Schema setup: ensure() is idempotent (insert-on-miss, return-on-hit),
// so this block is safe to run on every boot.
$blog = $categories->ensure(new Category(null, 'Blog', 'blog'));
$fields->ensure(new Field(null, $blog->id, 'title', 'Title', FieldType::Text));
$fields->ensure(new Field(null, $blog->id, 'body',  'Body',  FieldType::LongText));

// Persist an item.
$items->save(new Item(
    null,
    $blog->id,
    'hello-world',     // name:  URL-friendly identifier
    'Hello, world',    // label: human-readable title
    data: ['title' => 'Hello, world', 'body' => 'First post.'],
));

// Read back.
foreach ($items->findByCategory($blog->id) as $item) {
    echo $item->label . "\n";   // → Hello, world
}