Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions application/Controller/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class ErrorController
public function index()
{
// load views
require APP . 'view/_templates/header.php';
require APP . 'view/error/index.php';
require APP . 'view/_templates/footer.php';
view('_templates/header.php');
view('error/index.php');
view('_templates/footer.php');
}
}
18 changes: 9 additions & 9 deletions application/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class HomeController
public function index()
{
// load views
require APP . 'view/_templates/header.php';
require APP . 'view/home/index.php';
require APP . 'view/_templates/footer.php';
view('_templates/header.php');
view('home/index.php');
view('_templates/footer.php');
}

/**
Expand All @@ -33,9 +33,9 @@ public function index()
public function exampleOne()
{
// load views
require APP . 'view/_templates/header.php';
require APP . 'view/home/example_one.php';
require APP . 'view/_templates/footer.php';
view('_templates/header.php');
view('home/example_one.php');
view('_templates/footer.php');
}

/**
Expand All @@ -46,8 +46,8 @@ public function exampleOne()
public function exampleTwo()
{
// load views
require APP . 'view/_templates/header.php';
require APP . 'view/home/example_two.php';
require APP . 'view/_templates/footer.php';
view('_templates/header.php');
view('home/example_two.php');
view('_templates/footer.php');
}
}
39 changes: 21 additions & 18 deletions application/Controller/SongsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function index()
$songs = $Song->getAllSongs();
$amount_of_songs = $Song->getAmountOfSongs();

// load views. within the views we can echo out $songs and $amount_of_songs easily
require APP . 'view/_templates/header.php';
require APP . 'view/songs/index.php';
require APP . 'view/_templates/footer.php';
// load views. within the views we can echo out $songs and $amount_of_songs easily
view('_templates/header.php');
view('songs/index.php', ["songs" => $songs]);
view('_templates/footer.php');
}

/**
Expand All @@ -51,11 +51,11 @@ public function addSong()
// Instance new Model (Song)
$Song = new Song();
// do addSong() in model/model.php
$Song->addSong($_POST["artist"], $_POST["track"], $_POST["link"]);
$Song->addSong($_POST["artist"], $_POST["track"], $_POST["link"]);
}

// where to go after song has been added
header('location: ' . URL . 'songs/index');
redirect('songs/index');
}

/**
Expand All @@ -78,10 +78,10 @@ public function deleteSong($song_id)
}

// where to go after song has been deleted
header('location: ' . URL . 'songs/index');
redirect('songs/index');
}

/**
/**
* ACTION: editSong
* This method handles what happens when you move to http://yourproject/songs/editsong
* @param int $song_id Id of the to-edit song
Expand All @@ -95,16 +95,19 @@ public function editSong($song_id)
// do getSong() in model/model.php
$song = $Song->getSong($song_id);

// in a real application we would also check if this db entry exists and therefore show the result or
// redirect the user to an error page or similar

// load views. within the views we can echo out $song easily
require APP . 'view/_templates/header.php';
require APP . 'view/songs/edit.php';
require APP . 'view/_templates/footer.php';
// If the song wasn't found, then it would have returned false, and we need to display the error page
if ($song === false) {
$page = new \Mini\Controller\ErrorController();
$page->index();
} else {
// load views. within the views we can echo out $song easily
view('_templates/header.php');
view('songs/edit.php', ["song" => $song]);
view('_templates/footer.php');
}
} else {
// redirect user to songs index page (as we don't have a song_id)
header('location: ' . URL . 'songs/index');
redirect('songs/index');
}
}

Expand All @@ -123,11 +126,11 @@ public function updateSong()
// Instance new Model (Song)
$Song = new Song();
// do updateSong() from model/model.php
$Song->updateSong($_POST["artist"], $_POST["track"], $_POST["link"], $_POST['song_id']);
$Song->updateSong($_POST["artist"], $_POST["track"], $_POST["link"], $_POST['song_id']);
}

// where to go after song has been added
header('location: ' . URL . 'songs/index');
redirect('songs/index');
}

/**
Expand Down
2 changes: 2 additions & 0 deletions application/Core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/** For more info about namespaces plase @see http://php.net/manual/en/language.namespaces.importing.php */
namespace Mini\Core;

require APP . 'core/CoreFunctions.php';

class Application
{
/** @var null The controller */
Expand Down
15 changes: 15 additions & 0 deletions application/Core/CoreFunctions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Mini\Controller;

function view($path, $data = [])
{
foreach ($data as $k => $v) {
$$k = $v;
}
require APP . "view/{$path}";
}

function redirect($path) {
header('location: ' . URL . $path);
}