Creating a view to display a news list
Now, we will create a simple news list in a view named itemsList
. We will point to this view from NewsController
, so we have to:
- Create a
news
folder underbasic/views
, thatNewsController
will use as the base folder to search for the views to be rendered (according to the view names' rules explained in the previous chapter) - Create an
itemsList.php
file underbasic/views/news
Now, open basic/views/news/itemsList.php
, create an array with a list of data and display the output with a simple table of items:
<?php $newsList = [ [ 'title' => 'First World War', 'date' => '1914-07-28' ], [ 'title' => 'Second World War', 'date' => '1939-09-01' ], [ 'title' => 'First man on the moon', 'date' => '1969-07-20' ] ]; ?> <table> <tr> <th>Title</th> ...