Laminas module for accessing pimcore via its REST API
Laminas module for accessing pimcore via its REST API.
Installation of this module uses composer. For composer documentation, please refer to getcomposer.org.
php composer.phar require leuchtdiode/pimcore-rest-api
PimcoreRestApi to your
Currently there are the following features included:
- Retrieve document by ID
- Retrieve document by its path
- Search documents
- A view helper to print freetext of a document
In order to use the API, you have to specify a config set
pimcoreRestApi somewhere in your application (e.g.
You have to set the following parameters:
host: The host where your pimcore API resides (e.g. cms.company.com)
ssl: Defaults to false. Setting it to true will request API through SSL. (e.g. https://cms.company.com)
apiKey: The API-Key you generated in pimcore for your user
<?php $config = [ ... 'pimcoreRestApi' => [ 'host' => 'cms.company.com', 'ssl' => false, 'apiKey' => '1233298asd89as9das89d9as9d8as89da9sd98as9dad', ], ... ];
We are suggesting not to use the API directly, but the services the module is providing through service locator. At the moment there is only a document service included.
You can use
PimcoreRestApi\Service\Documents from service locator for retrieving documents:
- Get one document by ID
- Get one document by path
- Get all documents by path
The module is also providing a view helper for displaying freetext of a given document path.
$this->praDocument() in your view you can get an instance of the document view helper which provides the following methods at the moment:
This method tries to fetch a document by its path, searching for all of its WYSIWYG elements, concatenates them and outputs the text.
null gets returned if there was a problem fetching the document or finding WYSIWYG elements.
To minimize the API calls to the external pimcore system via its REST API we are suggesting setting up a storage cache provided by laminas-cache.
The module has already implemented caching. You only have to tell him.
Setting up is as simple as defining a factory in service locator which is returning a
Laminas\Cache\Storage\StorageInterface for key
You can use
PimcoreRestApi\Service\ConfigSynchronizing to synchronize specific CMS paths to your local system. There can be several strategies where the content is being synchronized too. The method
synchronize($rootPath) loads the strategy from the config and executes the synchronization.
$rootPath is the root path in the CMS you want to synchronize with all its children.
For now, there is only the FileSystemStrategy. You have to specify in your config file which strategy you want to use. Use the array key
Here is an example config for the FileSystem strategy.
'synchronizing' => [ 'type' => 'fileSystem', 'directory' => 'data/pimcoreRestApi' ]