PHP code example of strategio / megio-starter

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

    

strategio / megio-starter example snippets


class ArticleController extends Controller
{
    public function list(EntityManager $em, int $page): Response
    {
        $articles = $em->getRepository(Article::class)->findBy(['page' => $page])
        
        return $this->render(Path::viewDir() . '/controller/article.latte', [
            'articles' => $articles
        ]);
    }
}

class DownloadRequest extends Request
{
    // Inject custom dependencies here
    public function __construct(protected readonly EntityManager $em) 
    {
    }
    
    // Add request validations
    public function schema(array $data): array
    {
        return [
            'invoice' => Expect::structure([
                'type' => Expect::anyOf(
                    'invoice', 'proforma', 'invoice-annul', 'proforma-annul'
                ),
                'number' => Expect::string()->($data['invoice']['type'])
        
        ...
        
        $this->em->persist($invoice)
        $this->em->flush()
        
        return $this->json(['id' => $invoice->getId()]);
    }
}

return static function (RoutingConfigurator $routes): void {
    $routes->add('download', '/api/invoice/download')
        ->methods(['POST'])
        ->controller(\App\Admin\Http\Request\ExampleRequest::class)
        ->options(['auth' => false]);
    
    $routes->add('article', '/article/{page}')
        ->methods(['GET'])
        ->controller([\App\Http\Controller\ArticleController::class, 'list'])
        ->