bootiq/cms-api-vendor-nette
Composer 安装命令:
composer require bootiq/cms-api-vendor-nette
包简介
B!Q CMS api vendor - nette implementation
README 文档
README
Installation
For installation of Boot!Q CMS API vendor for Nette, use composer
composer require bootiq/cms-api-vendor-nette
Configuration
Add Boot!Q CMS API vendor for Nette to your extensions:
extensions: - BootIq\CmsApiVendor\Nette\DI\CmsApiVendorExtension
Register adapter for communication by defining biq_cms_adapter to services configuration:
services: biq_cms_adapter: class: BootIq\CmsApiVendor\Adapter\GuzzleSecurityTokenAdapter(GuzzleHttp\Client(), BootIq\CmsApiVendor\Response\ResponseFactory(), %cms_api.urn%, %cms_api.publicId%, %cms_api.secret%)
Finally define parameters for configuration (name are used above in adapter definition):
parameters: cms_api: urn: "<cms.example.com/api>" publicId: "<public ID>" secret: "<secret>"
Usage
Inject PageControlFactory into your Presenter and create PageControl component. For example:
/** * @var PageControlFactory * @inject */ public $pageControlFactory; /** * @return PageControl */ public function createComponentPageControl(): PageControl { $control = $this->pageControlFactory->create(); return $control; }
Now use PageControl component in your latte template:
{block content} <div id="banner"> <h1 n:block=title>Congratulations!</h1> </div> <div id="content"> <h2>You have successfully using Boot!Q CMS API vendor for Nette.</h2> <p> {control pageControl "/hello-workld-slug", false} </p> </div> {/block}
Modification
Fallbacks
If nothing is rendered, callback onNotRendered($mixed) is triggered. If one of the block is not rendered, callback onBlockNotRendered(Block $block, \Exception $exception) is triggered. Example of usage of our callback.
/** * @var PageControlFactory * @inject */ public $pageControlFactory; /** * @return PageControl */ public function createComponentPageControl(): PageControl { $control = $this->pageControlFactory->create(); $control->onNotRendered[] = function ($exception) { // DO SOMETHING WITH EXCEPTION }; $control->onBlockNotRendered[] = function ($block, $exception) { // DO SOMETHING WITH BLOCK OR EXCEPTION }; return $control; }
Own BlockControl
If you want use your own BlockControl, simply create new Control which implements BootIq\CmsApiVendor\Nette\Control\Block\BlockControlInterface. Then register it to PageControl in createComponent method:
/** * @var PageControlFactory * @inject */ public $pageControlFactory; /** * @return PageControl */ public function createComponentPageControl(): PageControl { $control = $this->pageControlFactory->create(); $myOwnBlockControl = new MyOwnBlockControl(); $control->addBlockControlByType($myOwnBlockControl, 'myOwnBlockType'); return $control; }
Logger
If you want log, what is going on in our PageControl simply set Logger to PageControl in createComponent method. Logger have to implement PSR-3 LoggerInterface. For example:
/** * @var PageControlFactory * @inject */ public $pageControlFactory; /** * @var LoggerInterface * @inject */ public $monologLogger; /** * @return PageControl */ public function createComponentPageControl(): PageControl { $control = $this->pageControlFactory->create(); $control->setLogger($this->monologLogger); return $control; }
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2018-02-08