1. Go to this page and download the library: Download hudsxn/canvas 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/ */
hudsxn / canvas example snippets
// Slow: Creates new string buffer each time
$html .= '<div>';
$html .= $content;
$html .= '</div>';
// Fast: O(1) array append operations
$sourceCode[] = '<div>';
$sourceCode[] = $content;
$sourceCode[] = '</div>';
// Join once at the end: implode('', $sourceCode)
use Hudsxn\Canvas\Objects\{Canvas, Page, Node};
use Hudsxn\Canvas\Response;
// Build the tree
$canvas = new Canvas('layouts/default');
$canvas->addChild(new Node('Header', ['logo' => 'logo.png']))
->addChild(new Node('Main', ['content' => 'Welcome!']))
->addChild(new Node('Footer'));
// Configure the page
$page = new Page($canvas);
$page->setTitle('Welcome to My Site')
->setMeta('description', 'A great website')
->enableCsp()
->allowScriptFrom("'self'")
->forceHttps();
// Render and send
$renderer = new MyRenderer();
$response = new Response($renderer, $page);
$response->send();
use Hudsxn\Canvas\Objects\{Canvas, Page};
use Hudsxn\Canvas\Renderers\SinglePageApplicationRenderer;
use Hudsxn\Canvas\Response;
// Create your page structure
$canvas = new Canvas('spa-app');
$canvas->addChild(new Node('Dashboard', ['userId' => 123]));
$page = new Page($canvas);
$page->setTitle('My React App')
->setMeta('viewport', 'width=device-width, initial-scale=1')
->enableCsp()
->allowScriptFrom("'self'", 'https://cdn.example.com')
->allowStyleFrom("'self'");
// Configure the SPA renderer
$renderer = new SinglePageApplicationRenderer();
$renderer->setJsUrl('/dist/app.js')
->setCssUrl('/dist/app.css');
// Send the response
$response = new Response($renderer, $page);
$response->send();