strategio/contentio-sdk

Contentio CRM网站的PHP SDK

v0.0.18 2023-01-10 14:10 UTC

README

(如果您在npmjs.com上阅读此README,请切换到https://github.com/strategio-digital/contentio-sdk)

关于

  • Contentio-SDK是一个完全可扩展的PHP & JS包,用于创建与Contentio REST API通信的定制网站。

  • 您可以用它作为您的电子商务网站或网站的"服务器端渲染(php)"和"客户端渲染(vue.js)"引擎。

  • 如果您不进行任何更改,SDK将渲染一个完整的电子商务网站,其外观将与https://contentio.store完全相同

安装指南

1. 对于经典使用

您必须克隆另一个存储库rokuc-cz

  1. git clone git@github.com:strategio-digital/rokuc-cz.git <my-project>
  2. rm -rf <my-project>/.git
  3. 转到"对于贡献者"中的第二步并继续。

2. 对于贡献者

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

3. 安装后

对于我们贡献者的重要注意事项

⚠️💥 不要忘记在更改这两个文件时使用 yarn publish

    1. package.json
    2. yarn.lock

经典使用示例

1. 添加自定义配置文件

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. 覆盖路由

app/config/app.neon

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

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. 覆盖任何操作的模板

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. 向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. 创建图片缩略图

{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="...">