PHP code example of imagenator / start

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

    

imagenator / start example snippets


  $router->addRoute('GET', '/', ['UploadController', 'showPage']);

  $router->addRoute('метод(GET или POST)', 'путь', ['название класса', 'метод класса']);

  $router->addRoute('GET', '/', 'Imagenator\Controller\MyFunction');

  $router->addRoute('POST', '/', function ($response, $request) {
    /*some code*/
  });

namespace Imagenator\Controller;

class SecondController
{
    /**
     * @param $response
     * котроллер для формирования ответа
     * @param $request
     * содержит в себе информацию о запросе
     * @return mixed
     */
    public function blablabla($response, $request)
    {
        return $response->setBody("Hello))"); //Вывести на экран "Hello))"
    }
}

/**
* @param $response
* @param $request
* @return mixed
*/
public function form($response, $request)
{
    return $response->view('form') // Выбрать шаблон form из папки /templates, (без .twig)
        ->setStatus(201) //Указать что код ответа 201
        ->setHeader('Content-type', 'text/html;') //Указать Content-type
        ->setBody('sample text') //Выводит на экран текст (отменяет действие view)
        ->redirect('example.com', 'code (optional)'); //создаёт редирект
    /**
     * ВАЖНО вернуть $response отбратно используя return
     */
}

public function page($response, $request)
{
    $name = $request->request->get('name'); //получаем из POST поле 'name'
    return $response->view('index', ['name' => $name]) //Возвращаем шаблон с параметрами (в нашем случае с $name)
        ->setStatus(202); //Устанавливаем статус 202
}