PHP code example of alanvdb / app

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

    

alanvdb / app example snippets


 declare(strict_types=1);

namespace App;

use AlanVdb\Controller\MainController;
use AlanVdb\Controller\BlogController;

return [
    ['home', 'GET', '/', [MainController::class, 'index']],
    ['blog', 'GET', '/blog', [BlogController::class, 'index']],
    ['blogPost', 'GET', '/blog/{slug}', [BlogController::class, 'show']],
];

 declare(strict_types=1);

namespace AlanVdb\Controller;

use Psr\Http\Message\ResponseInterface;

class MainController extends AbstractController
{
    public function index(): ResponseInterface
    {
        $params = $this->getCommonTemplateParams();
        $document = $this->twig->render('home.twig', $params);
        return $this->createResponse($document);
    }

    protected function getCommonTemplateParams(): array
    {
        return [
            'uriGenerator' => $this->request->getAttribute('uriGenerator'),
        ];
    }
}

 declare(strict_types=1);

namespace App\Model\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'blogs')]
class Blog
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private int $id;

    #[ORM\Column(type: 'string', length: 255)]
    private string $title;

    #[ORM\Column(type: 'text')]
    private string $content;

    #[ORM\Column(type: 'datetime')]
    private \DateTime $createdAt;

    // Getters and setters...
}
bash
bin/doctrine.php orm:schema-tool:create
bash
bin/doctrine.php orm:schema-tool:update --force