PHP code example of comfyphp / core

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

    

comfyphp / core example snippets




 = new ComfyPHP\Core();
$router = $core->getRouter();

// search for index.php in src/pages (by default)
$router->get("/", "./index");

// return json
$router->get("/hello", function (): string {
    $response = [
        "message" => "Hello, World!",
    ];

    header("Content-Type: application/json");
    return json_encode($response);
});

$core->run();



 = new ComfyPHP\Core();

$core->fileBasedRouter();

$core->run();

$core = new ComfyPHP\Core();
$router = $core->getRouter();

$router->get("/", "./index");
$router->get("/alphabet", "./abc");

$core = new ComfyPHP\Core();

$core->fileBasedRouter();

echo $_ENV["COOKIE_DOMAIN"];

$tools = new ComfyPHP\Tools();

$log = $tools->useLog();
$log("Hello World!");
// or
$tools->useLog("Hello World!");

// result:
// <script>console.log("Hello World!")</script>

$err = $tools->useError();
$err("Goodbye World!");
// or
$tools->useError("Goodbye World!");

// result:
// <script>console.error("Hello World!")</script>

$f = $tools->useFilter();
$f("<script>alert('hack')</script>");
// or
$tools->useFilter("<script>alert('hack')</script>");

// result:
// &lt;script&gt;alert(&apos;hack&apos;)&lt;/script&gt;

$_ENV["ENV"];
$GLOBALS["ROOT"];
$GLOBALS["CONFIG_VERSION"];
$GLOBALS["CONFIG_MINIMIZE"];
$GLOBALS["CONFIG_PAGE_PATH"];
$GLOBALS["SYSTEM_DEBUG"];

├── public
│   └── index.php
├── src
│   └── pages
│       ├── _document.php
│       └── index.php
├── .env.development.local
├── .env.development
├── .env.production.local
├── .env.production
├── .env.local
├── .env
└── comfy.config.php