PHP code example of professionalweb / pwf

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

    

professionalweb / pwf example snippets




(new \project\Application())->run();

namespace project;

use pwf\basic\RouteHandler;
use Symfony\Component\Yaml\Yaml;

class Application extends \pwf\basic\Application
{

    public function __construct()
    {
        parent::__construct(Yaml::parse(file_get_contents('../project/config/config.yaml')));

        RouteHandler::registerHandler('/',
            '\project\controllers\MainController::index');

        $this->getResponse()->setHeaders([
            "Access-Control-Allow-Headers: Content-Type",
            "Content-Type:text/html; charset=utf-8"
        ]);
    }
}



namespace project\controllers;

class MainController extends \pwf\basic\WebController
{

    public function index()
    {
        $this->title = 'Main page';

        return $this->render('project/views/main/index.php',
            [
                'name' => 'World!'
            ]);
    }
}

class PostModel extends \pwf\basic\DBModel
{

    public function __construct(array $attributes = [])
    {
        parent::__construct(attributes);
        $this->table('post');
    }
}