PHP code example of webiik / staticpage

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


    public function run(): void
    {
        // Page URI
        $uri = '/foo/bar/';
        
        // Page template
        $page = '<h1>Meow World!</h1>';
    
        // Save static file the web server will try to serve with every next request  
        $staticPage = new Webiik\StaticPage\StaticPage();
        $staticPage->save($page, $uri);
    
        // Show dynamic page when the server didn't serve the static page  
        echo $page;
    }
    

setDir(string $dir): void

$staticPage->setDir('./_site');

save(string $data, string $uri, string $file = 'index.html'): void

$staticPage->save('<h1>Meow World!</h1>', '/foo/bar/');

delete(bool $test = true): void

$staticPage->delete();
nginx
    location / {
        try_files /_site${uri} /_site${uri}index.html $uri $uri/ /index.php?$query_string;
    }
    
shell script
php StaticPage.php /absolute/path/to/static/_site true