PHP code example of webiik / ssr

1. Go to this page and download the library: Download webiik/ssr 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/ */

    

webiik / ssr example snippets


    // Render the component on server
    $ssr = new \Webiik\Ssr\Ssr();
    $engine = new \Webiik\Ssr\Engines\NodeJs();
    $engine->setTmpDir(__DIR__);
    $ssr->useEngine($engine);
    $html = $ssr->render('build/index.js', 'Meow', ['name' => 'Dolly'], [
        'ssr' => true,
    ]);
   
    // Load JS libs on client 
    echo '<script src="build/index.js"></script>';
   
    // Print server-side rendered component on client
    echo $html;
    
    
// To enable cache you MUST set cache dir and add 'cache' key to $renderOptions.
// To prevent cache conflicts cache key MUST be unique.
$ssr->setCacheDir(__DIR__);
$html = $ssr->render('index.js', 'Meow', ['name' => 'Dolly'], [
    'ssr' => true,
    'cache' => 'Meow',
    'expires' => 1, // 1 = one hour, 0 = never expires
]);   

    $ssr->setFwJsMask('vue', 'window.WebiikVue.%1$s("%2$s", "%3$s", "%4$s")');
    

    $ssr->setDefaultFramework('vue');
    

    $html = $ssr->render('index.js', 'Meow', ['name' => 'Dolly'], [
        'fw' => 'vue',
    ]);
    

    $ssr->useEngine(new YourCustomEngine());