<?php
class MainController {
  public function actionIndex(){
    $model = new Model;
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
      $model->save($_POST['title'], $_POST['article']);
    }
    $data = $model->getAllArticles();
    $this->render($data);
  }
  private function render($data){
    $view = file_get_contents('template.tpl');
    $content = '';
    while ($row = $data->fetchAll() ) {
      $content .= "<h3>{$row['title']}</h3>";
      $content .= "<p>{$row['article']}</p>";
    }
    echo str_replace('{{content}}', $content, $view);
  }
}