55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
||
/**
|
||
* @package Bicycle
|
||
* @author Egor Isaev
|
||
* @description IndexController.php
|
||
* @copyright (c) 03/06/2026
|
||
*/
|
||
|
||
namespace App\Controller;
|
||
|
||
use App\Repositories\BudgetRepository;
|
||
use System\Classes\Controller;
|
||
use System\Classes\HTTP\Client\Curl;
|
||
use System\Classes\HTTP\Client\Request as HttpRequest;
|
||
use System\Classes\MyException;
|
||
|
||
/**
|
||
* Демонстрационный контроллер главной страницы.
|
||
*/
|
||
class IndexController extends Controller
|
||
{
|
||
/**
|
||
* @return string
|
||
* @throws MyException
|
||
*/
|
||
public function indexAction(): string
|
||
{
|
||
$budgetR = new BudgetRepository();
|
||
|
||
$budgetR->getB();
|
||
|
||
return $this->render('index');
|
||
}
|
||
|
||
/**
|
||
* Демонстрация POST-запроса с JSON-телом к внешнему API.
|
||
*
|
||
* @return string
|
||
* @throws \JsonException
|
||
*/
|
||
public function postAction(): string
|
||
{
|
||
// POST с JSON-телом
|
||
$response = (new Curl())->execute(
|
||
HttpRequest::factory('https://jsonplaceholder.typicode.com/posts')
|
||
->method('POST')
|
||
->json(['title' => 'Bicycle', 'body' => 'test', 'userId' => 1])
|
||
);
|
||
|
||
$created = $response->isSuccess() ? $response->json() : [];
|
||
|
||
return $this->render('index', ['created' => $created]);
|
||
}
|
||
}
|