Download the PHP package daccess1/yii2-tilda-api without Composer
On this page you can find all versions of the php package daccess1/yii2-tilda-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-tilda-api
Yii2 Tilda Api
Read in other languages: Русский
Tilda platform api extension for Yii2
This is a fork of nariman924/yii2-tilda-api project, which seems to be abandoned for a couple of years.
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Once the extension is installed, include this in components section of your common/config/main-local.php
file:
Apply required migrations
Usage
The two most common goals of this extension are saving Tilda pages to lhe local database and then showing them to the end user. The following instruction shows some common usage patterns for this extension. All examples assume that you are using Gii-generated CRUD.
Saving pages
To render the list of the pages from Tilda project, you can use the renderPageSelect
method. It's designed to be used with the ActiveForm generated with Gii, and requires no additional setup by default. Simply replace your form field that stores Tilda page id with this code:
This widget takes all the same values as default ActiveForm input field. You can also set the project ID (integer) as a third parameter. If you don't, the defaultProjectID
setting will be used. As the result, the HTML select with listed Tilda pages will be rendered into your form, and it's input will be treated as any other model field.
After selecting the page, you now want to save it to the local storage. In order to do so you should update actionCreate
and actionUpdate
functions of your Controller like this:
This will save page body HTML code and assets to your local server.
Rendering pages
After your page was saved to the local storage, you can render it with the registerAssets
and renderHtml
methods of the extension. This will require two steps to implement:
In your controller action register the required assets:
The first parameter is the current \yii\web\Controller
instance, and the second one is the Tilda page ID.
Then in your view you can render HTML like this
Webhook
Tilda has an option to notify your app about any pages published in your projects via a webhook. However, it has some restrictions on it's usage (see more in Tilda API docs). One of the ways to implement Webhook would be like this:
Methods
After registering the component and applying required migrations, you can access it's methods anywhere in your code. However, the most common usage case was already described above.
renderPageSelect
Returns ActiveForm-compatible HTML select input, which lists all pages from selected project. If no $projectID
is provided the defaultProjectID
setting is used instead.
getPage
Saves tilda page and it's assets to the local database. Note: Tilda's default jQuery (1.10.2) is not downloaded (to prevent conflicts with your Yii2 jQuery asset).
registerAssets
Registers page's assets (CSS and JS). The first parameter is the current \yii\web\Controller
instance, and the second one is the Tilda page ID.
renderHtml
Returns HTML code of the selected page.
listPages
Returns list of pages in project as array of ['id' => 'title']
arrays. If no $projectID
is provided the defaultProjectID
setting is used instead.
loadPage
Returns the array of data form the local copy of the page.
Notes
You should consider that current Tilda core css settings conflict with Bootstrap (provided with Yii2 by default). To avoid conflicts, you could either don't use bootstrap.css
and Tilda at the same page, or fix box-sizing
property of elements in your own stylesheet.
License
This software is licensed under MIT license. For more information see LICENSE.