strategio/contentio-sdk

PHP SDK for Contentio CRM websites


License
Other

Documentation

contentio-sdk

(If you read this readme on npmjs.com, switch to https://github.com/strategio-digital/contentio-sdk)

About

  • Contentio-SDK is a fully extendable PHP & JS package for creating custom websites that's communicating with the Contentio REST API.

  • You can use it as "server-side-rendering (php)" AND "client-side-rendering (vue.js)" engine for your e-shop or website.

  • If you don't make any changes, the SDK will render a complete e-shop that will look exactly like https://contentio.store

Installation guide

1. For classic usage

You have to clone another repository rokuc-cz

  1. git clone git@github.com:strategio-digital/rokuc-cz.git <my-project>
  2. rm -rf <my-project>/.git
  3. Go to second step in "For contributors" and continue.

2. For contributors

  1. git clone git@github.com:strategio-digital/contentio-sdk.git
  2. ./project.sh serve
  3. ./project.sh app
  4. yarn && yarn dev
  5. composer i
  6. composer phpstan

3. After installation

IMPORTANT NOTES FOR OUR CONTRIBUTORS

⚠️💥 Don't forget to yarn publish when you make changes in these 2 files:

    1. package.json
    2. yarn.lock

Examples for classic usage

1. Adding custom config file

In www/index.php

$container = (new Bootstrap())
    ->projectRootPath(__DIR__ . '/../')
    ->configure([
        __DIR__ . '/../vendor/strategio/contentio-sdk/config/app.neon',
        //__DIR__ . '/../config/app.neon' // <--- uncomment this
    ]);

$container->getByType(App::class)->run($container);

2. Overriding routes:

In app/config/app.neon

services:
    #routerFactory: Strategio\Router\RouterFactory # <--- uncomment this

In app/Router/RouterFactory.php

class RouterFactory extends \ContentioSdk\Router\RouterFactory
{
    public function createRoutes(): UrlMatcher
    {
        $routes = parent::createRoutes();
       
        // uncomment this --->
        /*$this->add('article_detail', '/clanky/{slug}', [
            \Strategio\Controller\ArticleController::class, 
            'index'
        ]);*/ 
        
        return $routes;
    }
}

3. Overriding template of any action

In app/Controller/ArticleController.php

class ArticleController extends \ContentioSdk\Controller\ArticleController
{
    #[Template(path: __DIR__ . '/../../view/controller/article.latte')]
    public function index(string $slug): void
    {
        parent::index($slug);
    }
}

4. Making async request to API

public function index(string $slug): void
{
    $this->addRequest('first', 'GET', "article/show-one", [
        'json' => [
            'slug' => $slug,
        ]
    ]);
    
    $this->addRequest('second', 'GET', "article/show-one", [
        'json' => [
            'slug' => $slug,
        ]
    ]);
    
    $responses = $this->dispatchRequests('Article Detail');
    
    // first article as array -->
    $a1 = json_decode($responses['first']->getBody()->getContents(), true);
    
    // second article as array -->
    $a2 = json_decode($responses['second']->getBody()->getContents(), true);
    
    $this->template->articles = [$a1, $a2];
}

5. Creating image thumbnail

{varType ContentioSdk\Component\Thumbnail\ThumbGen $thumbGen}
{var $thumb = $thumbGen->create('<slug>/article/56/test.png', 500, null, 'SHRINK_ONLY', 80)}
<img loading="lazy" src="{$thumb->getSrc()}" width="{$thumb->getWidth()}" height="{$thumb->getHeight()}" alt="...">