1. Go to this page and download the library: Download ffperera/cubo 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/ */
ffperera / cubo example snippets
class PostList extends Action
{
public function __construct(private IPostRepository $repo) {}
public function run(Controller $controller): void
{
// initialize the repository with the PDO connection
try {
$this->repo->init(['PDO' => $controller->get('PDO')]);
}
catch (\Exception $e) {
// TODO: handle the exception
}
// fetch posts from the repository
$posts = $this->repo->getPosts();
$view = $controller->getView();
$view->set('posts', $posts);
$view->set('title', 'POSTS');
$view->set('post-list-intro', 'This is the list of posts');
$view->setLayout('/Pub/layout/main.php');
$view->setTemplate('main', '/Pub/layout/post_list.php');
$view->set('metatitle', 'List of Posts');
$view->set('metadesc', 'Published posts');
$view->set('canonical', '/blog/');
}
}
$controller = new Controller($routes, $logger, $debug=true);
try {
$view = $controller->run();
if ($view) {
$render = new Render($view, $srcDir);
$render->send();
}
} catch (Exception $e) {
// Handle exceptions and errors
echo 'Error: ' . $e->getMessage();
}
// inside the Action::run() method
$view = $controller->getView();
$view->setLayout('layout.php');
$view->setTemplate('content', 'content.php');
// inside the Action or in the main entry point
if ($view && $view instanceof \FFPerera\Cubo\View) {
$render = new Render($view, $srcDir);
$render->send();
}