PHP code example of statical / slim-static

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

    

statical / slim-static example snippets


$app->get('/hello-world', function()
{
	$app = Slim::getInstance();

	$app->view()->display('hello.html', array(
        'name' => $app->request()->get('name', 'world')
    ));
});

$app->run();

Route::get('/hello-world', function()
{
	View::display('hello.html', array(
        'name' => Input::get('name', 'world')
    ));
});

App::run();

use Slim\Slim;
use Statical\SlimStatic\SlimStatic;

$app = new Slim();

SlimStatic::boot($app);

# Allow any registered proxy to be called anywhere in the `App\Name` namespace

Statical::addNamespace('*', 'App\\Name\\*');

App::expires('+1 week');
App::halt();

$debug = Config::get('debug');
Config::set('log.enable', true);

# Note that you could also use:
$debug = App::config('debug');
App::config('log.enable', true);

# $app->foo = 'bar'
Container::set('foo', 'bar');

# $bar = $app->foo
$bar = Container::get('foo');

Container::singleton('log', function () {...});
$rawClosure = Container::protect(function () {...});

$avatar = Input::file('avatar');
$username = Input::get('username', 'default');
$password = Input::post('password');

Log::info('My info');
Log::debug('Degug info');

$path = Request::getPath();
$xhr = Request::isAjax();

Response::redirect('/success');
Response::headers->set('Content-Type', 'application/json');

Route::get('/users/:id', function ($id) {...});
Route::post('/users',  function () {...});
Route::urlFor('admin');

View::display('hello.html');
$output = View::render('world.html');

class PaymentProxy extends \Statical\BaseProxy {}

# create our PaymentService class
$instance = new \PaymentService();

$alias = 'Payment';             # The static alias to call
$proxy = 'PaymentProxy';        # The proxy class you just created

Statical::addProxyInstance($alias, $proxy, $instance);

# Now we can call PaymentService methods via the static alias Payment
Payment::process();

# Register our service with Slim's DI container
Container::set('payment', function () {
    return new \PaymentService();
});


$alias = 'Payment';             # The static alias to call
$proxy = 'PaymentProxy';        # The proxy class you just created
$id = 'payment';                # The id of our service in the Slim container

Statical::addProxyService($alias, $proxy, Container::getInstance(), $id);

# Now we can call PaymentService methods via the static alias Payment
Payment::process();