PHP code example of daccess1 / yii2-tilda-api

1. Go to this page and download the library: Download daccess1/yii2-tilda-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

daccess1 / yii2-tilda-api example snippets


    'components' => [
         ...
         'tilda' => [
             'class' => 'daccess1\tilda\TildaApi',
             'publicKey' => '**********',
             'secretKey' => '**********',
             // Change URL if needed. Don't forget to set protocol
             // to https:// when moving to production.
             'assetsUrl' => 'http://'.$_SERVER['HTTP_HOST'].'/tilda',
             // Change 'public_html' to the frontend web directory if needed
             // (default Yii2 directory is 'frontend/web')
            'assetsPath' => dirname(dirname(__DIR__)).'/public_html/tilda',
             //Optional default project ID (integer)
             //'defaultProjectID' => *****
         ],
     ],

<?= Yii::$app->tilda->renderPageSelect($model,'your_field_id'); 

if ($model->load(Yii::$app->request->post()) && $model->save()) {
    //insert this line
    Yii::$app->tilda->getPage($model->your_field_id);
    
    return $this->redirect(['view', 'id' => $model->id]);
}

Yii::$app->tilda->registerAssets($this,$model->tilda_page_id);

<?= Yii::$app->tilda->renderHtml($model->tilda_page_id) 

public function actionWebhook()
    {
        $get = \Yii::$app->request->get();

        // Check request public key
        if (!\Yii::$app->tilda->verifyPublicKey($get['publickey']))
            throw new \yii\web\ForbiddenHttpException("PublicKey dosen't match");
        
        if (!isset($get['save'])) {
            // If this is actual Tilda webhook request,
            // create cURL request client 
            // Set 'baseUrl' to your current webhook Url
            $client = new Client([
                'transport' => 'yii\httpclient\CurlTransport',
                'baseUrl' => 'http://domain.com/index.php?r=tilda/webhook'
            ]);
            try {
                $client->createRequest()
                    ->setMethod('get')
                    ->setData(['save' => 1, 'page' => $get['pageid'], 'publickey' => $get['publickey']])
                    ->setOptions([
                        // Setting timeout and data return transfer
                        // options of request to prevent waiting until
                        // page download completes
                        CURLOPT_CONNECTTIMEOUT => 1,
                        CURLOPT_TIMEOUT => 1,
                        CURLOPT_RETURNTRANSFER => false,
                        CURLOPT_FORBID_REUSE => true,
                        CURLOPT_DNS_CACHE_TIMEOUT => 10,
                        CURLOPT_FRESH_CONNECT => true,
                    ])
                    ->send();
            } catch (\yii\httpclient\Exception $e) {
                // Returning success result to Tilda webhook
                \Yii::$app->response->format = \yii\web\Response::FORMAT_HTML;
                return "ok";
            }
        } else {
            // Else if this is cURL recursive request, perform
            // page download 
            \Yii::$app->tilda->getPage($get['page']);
        }

        \Yii::$app->response->format = \yii\web\Response::FORMAT_HTML;
        return "ok";
    }

Yii::$app->tilda->renderPageSelect($model,'your_field_id',$projectID);

Yii::$app->tilda->getPage($pageID)

Yii::$app->tilda->registerAssets($this,$pageID);

Yii::$app->tilda->renderHtml($pageID)

Yii::$app->tilda->listPages($projectID)

$page = Yii::$app->tilda->loadPage($pageID);

php yii migrate --migrationPath=@vendor/daccess1/yii2-tilda-api/migrations