PHP code example of mezon / application

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

    

mezon / application example snippets


$callbackProvider = new SomeCallbackClass();

return 
    [
        [
            'route' => '/news/' ,  // your route
            'callback' => 'displayNewsLine'    // this must be the method name of your 
                                               // Application derived class
        ] , 
        [
            'route' => '/news/[i:news_id]/' ,    // your route
            'callback' => 'displayExactNews' ,   // this must be the method name of your 
            'method' => 'POST'                   // Application derived class
        ] , 
        [
            'route' => '/some-route/' , 
            'method' => 'GET' , 
            'callback' => [  // here we specify callback as pair [object, method]
                callbackProvider , 
        	'someMethod'
            ]        	
        ]
    ];

$app->loadRoutesFromConfig( './conf/my-config.php' );

class ExampleApplication extends CommonApplication
{
    /**
     * Constructor.
     */
    function __construct( $template )
    {
        parent::__construct( $template );
    }

    function actionSimplePage()
    {
        return [ 
            'title' => 'Route title' , 
            'main' => 'Route main'
        ];
    }
}

class ExampleApplication extends CommonApplication
{
    /**
     * Constructor.
     */
    function __construct($template)
    {
        parent::__construct($template);
    }

    function actionSimplePage()
    {
        return [ 
            'title' => 'Route title' , 
            'main' => new View('Generated main content')
        ];
    }
}

class ExampleApplication extends CommonApplication
{
    /**
     * Constructor.
     */
    function __construct($template)
    {
        parent::__construct($template);

	// loading config on custom path
	$this->loadRoutesFromConfig('./my-routes.json');
    }

    function route1()
    {
        return [ 
            // here result
        ];
    }

    function route2()
    {
        return [ 
            // here result
        ];
    }
}

function __construct($template)
{
    parent::__construct($template);

    $this->loadRoutesFromConfigs(['./conf/my/routes.json', './conf/my-routes.php']);
}

function __construct($template)
{
    parent::__construct($template);

    $this->loadRoutesFromDirectory('./conf');
}

// here $template is an instance of the \Mezon\HtmlTemplate\HtmlTemplate class
// and 'block-name' is a block name in this class
$view = new \Mezon\Application\ViewStatic($template, 'block-name');