I am trying to create a content management system using Twig and PHP, but when I open the page, it says that there are no entries when there are. I have verified this using a var_dump()
.
Code for the route:
$app->get('/articles', function() use ($app) {
$approved_articles = $db_bsa->query("
SELECT id, label, slug
FROM approved_articles
")->fetchAll(PDO::FETCH_ASSOC);
var_dump($approved_articles);
$app->render('main/articles.php');
})->name('articles');
Code for the view:
{% extends 'templates/default.php' %}
{% block title %}Articles{% endblock %}
{% block content %}
<article class="article">
<header>
<h2>Articles</h2>
</header>
<footer>
<p class="post-info">A Directory Style Listing of our Active Articles</p>
</footer>
{% if approved_articles %}
<ul>
{% for approved_article in approved_articles %}
<li>{{ approved_article.label }}</li>
{% endfor %}
</ul>
{% else %}
<p>No articles at the moment...</p>
{% endif %}
</article>
{% endblock %}
Also, a longer chain with more background info is posted here: https://www.codecourse.com/forum/topics/problems-using-twig-and-php/329
Thanks for the help!