Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/*
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ of the original MINI, made by [JaoNoctus](https://github.com/JaoNoctus). Big tha

## Requirements

- PHP 5.6 or PHP 7.0
- PHP 5.6 or PHP 7.x (PHP 8.0 should also work fine)
- MySQL
- mod_rewrite activated (see below for tutorials)
- basic knowledge of Composer for sure
Expand All @@ -39,10 +39,10 @@ Vagrant-file (defines your Vagrant box) and a demo bootstrap.sh which automatica
PHPMyAdmin, git and Composer, sets a chosen password in MySQL and PHPMyadmin and even inside the application code,
downloads the Composer-dependencies, activates mod_rewrite and edits the Apache settings, downloads the code from GitHub
and runs the demo SQL statements (for demo data). This is 100% automatic, you'll end up after +/- 5 minutes with a fully
running installation of MINI3 inside an Ubuntu 14.04 LTS Vagrant box.
running installation of MINI3 inside an Ubuntu 20.04 Vagrant box on PHP 7.4.x.

To do so, put `Vagrantfile` and `bootstrap.sh` from `_vagrant` inside a folder (and nothing else).
Do `vagrant box add ubuntu/trusty64` to add Ubuntu 14.04 LTS ("Trusty Thar") 64bit to Vagrant (unless you already have
Do `vagrant box add ubuntu/focal64` to add Ubuntu 20.04 64bit to Vagrant (unless you already have
it), then do `vagrant up` to run the box. When installation is finished you can directly use the fully installed demo
app on `192.168.33.66`. As this just a quick demo environment the MySQL root password and the PHPMyAdmin root password
are set to `12345678`, the project is installed in `/var/www/html/myproject`. You can change this for sure inside
Expand Down Expand Up @@ -92,7 +92,7 @@ server {

location / {
index index.php;
try_files /$uri /$uri/ /index.php?url=$uri;
try_files /$uri /$uri/ /index.php?url=$uri&$args;
}

location ~ \.(php)$ {
Expand Down
2 changes: 1 addition & 1 deletion _vagrant/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "ubuntu/trusty64"
config.vm.box = "ubuntu/focal64"

# Create a private network, which allows host-only access to the machine using a specific IP.
config.vm.network "private_network", ip: "192.168.33.66"
Expand Down
4 changes: 2 additions & 2 deletions _vagrant/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ sudo apt-get update
sudo apt-get -y upgrade

sudo apt-get install -y apache2
sudo apt-get install -y php5
sudo apt-get install -y php

sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $PASSWORD"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $PASSWORD"
sudo apt-get -y install mysql-server
sudo apt-get install php5-mysql
sudo apt-get install php-mysql

sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean true"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/app-password-confirm password $PASSWORD"
Expand Down
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');
}
}
19 changes: 10 additions & 9 deletions application/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ 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 +34,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 +47,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
11 changes: 8 additions & 3 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 Expand Up @@ -37,7 +39,8 @@ public function __construct()
$this->url_controller = new $controller();

// check for method: does such a method exist in the controller ?
if (method_exists($this->url_controller, $this->url_action)) {
if (method_exists($this->url_controller, $this->url_action) &&
is_callable(array($this->url_controller, $this->url_action))) {

if (!empty($this->url_params)) {
// Call the method and pass arguments to it
Expand All @@ -52,11 +55,13 @@ public function __construct()
// no action defined: call the default index() method of a selected controller
$this->url_controller->index();
} else {
header('location: ' . URL . 'error');
$page = new \Mini\Controller\ErrorController();
$page->index();
}
}
} else {
header('location: ' . URL . 'error');
$page = new \Mini\Controller\ErrorController();
$page->index();
}
}

Expand Down
16 changes: 16 additions & 0 deletions application/Core/CoreFunctions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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);
}
9 changes: 8 additions & 1 deletion application/Core/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ private function openDatabaseConnection()
// For example, fetch mode FETCH_ASSOC would return results like this: $result["user_name] !
// @see http://www.php.net/manual/en/pdostatement.fetch.php
$options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING);

// setting the encoding is different when using PostgreSQL
if (DB_TYPE == "pgsql") {
$databaseEncodingenc = " options='--client_encoding=" . DB_CHARSET . "'";
} else {
$databaseEncodingenc = "; charset=" . DB_CHARSET;
}

// generate a database connection, using the PDO connector
// @see http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/
$this->db = new PDO(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=' . DB_CHARSET, DB_USER, DB_PASS, $options);
$this->db = new PDO(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME . $databaseEncodingenc, DB_USER, DB_PASS, $options);
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion application/Model/Song.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getSong($song_id)
$query->execute($parameters);

// fetch() is the PDO method that get exactly one result
return $query->fetch();
return ($query->rowcount() ? $query->fetch() : false);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
define('DB_NAME', 'mini');
define('DB_USER', 'root');
define('DB_PASS', '12345678');
define('DB_CHARSET', 'utf8');
define('DB_CHARSET', 'utf8mb4');