diff --git a/.htaccess b/.htaccess deleted file mode 100644 index c6fe4d8..0000000 --- a/.htaccess +++ /dev/null @@ -1,20 +0,0 @@ -# Necessary to prevent problems when using a controller named "index" and having a root index.php -# more here: http://httpd.apache.org/docs/2.2/content-negotiation.html -Options -MultiViews - -# Activates URL rewriting (like myproject.com/controller/action/1/2/3) -RewriteEngine On - -# Disallows others to look directly into /public/ folder -Options -Indexes - -# When using the script within a sub-folder, put this path here, like /mysubfolder/ -# If your app is in the root of your web folder, then leave it commented out -RewriteBase /php-mvc-advanced/ - -# General rewrite rules -RewriteCond %{REQUEST_FILENAME} !-d -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-l - -RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 3f2a92e..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,8 +0,0 @@ -CHANGE LOG -========== - -**January 4th 2014** -- fixed htaccess issue when there's a controller named "index" and a base index.php (which collide) - -**December 29th 2013** -- fixed case-sensitive model file loading (thanks "grrnikos") diff --git a/README.md b/README.md index a5ecbfd..1880600 100644 --- a/README.md +++ b/README.md @@ -1,178 +1,3 @@ -# PHP-MVC-ADVANCED +# MINI2 -*Note: This is the same like [panique/php-mvc](https://github.com/panique/php-mvc), but with additional features.* -*This repo is in development, more to come...* - -### New in the advanced version: - -1. Twig -2. SASS-compiler in PHP ! The SASS compiling is optional, you can delete the scss folder and just use classic .css, too. - I've used https://github.com/panique/laravel-sass here. - -An extremely simple and easy to understand MVC skeleton application, reduced to the max. -Everything is **as simple as possible**, as **manually as possible** and as readable as possible. -This project is - by intention - NOT a full framework, it's a bare-bone structure, written in -purely native PHP ! The php-mvc skeleton tries to be the extremely slimmed down opposite of big frameworks -like Zend2, Symfony or Laravel. - -[![Donate with PayPal banner](_tutorial/donate-with-paypal.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=P5YLUK4MW3LDG) - -[![Donate with Flattr banner](_tutorial/donate-with-flattr.png)](https://flattr.com/submit/auto?user_id=panique&url=https%3A%2F%2Fgithub.com%2Fpanique%2Fphp-mvc-advanced) - -## Why does this project exist ? - -One of the biggest question in the PHP world is "How do I build an application ?". -It's hard to find a good base, a good file structure and useful information on that, but at the same time -there are masses of frameworks that might be really good, but really hard to understand, hard to use and extremely -complex. This project tries to be some kind of naked skeleton bare-bone for quick application building, -especially for the not-so-advanced coder. - -### Goals of this project: - -- give people a clean base MVC structure to build a modern PHP application with -- teach people the basics of the Model-View-Controller architecture -- encourage people to code according to PSR 1/2 coding guidelines -- promote the usage of PDO -- promote the usage of external libraries via Composer -- promote development with max. error reporting -- promote to comment code -- promote the usage of OOP code -- using only native PHP code, so people don't have to learn a framework - -## Support forum - -If you are stuck with something even AFTER reading and following the install tutorials and the quick-manual, then feel -free to ask in the [official forum](http://forum.php-mvc.net/). Note that this forum is fresh and new, more content -will come over time. - -## Installation - -1. First, install Composer ([How to install Composer on Ubuntu, Debian or Windows 7/8](http://www.dev-metal.com/install-update-composer-windows-7-ubuntu-debian-centos/)). -That's some kind of PHP standard now and there's no reason to work without Composer. If you think "I don't need/want -Composer" then you are doing something seriously wrong! - -2. Copy this repo into a public accessible folder on your server. -Common techniques are a) downloading and extracting the .zip / .tgz by hand, b) cloning the repo with git (into var/www) - -``` -git clone https://github.com/panique/php-mvc-advanced.git /var/www -``` - -or c) getting the repo via Composer (here we copy into var/www) - -``` -composer create-project panique/php-mvc-advanced /var/www dev-master -``` - -3. Install mod_rewrite, for example by following this guideline: -[How to install mod_rewrite in Ubuntu](http://www.dev-metal.com/enable-mod_rewrite-ubuntu-12-04-lts/) - -4. Run the SQL statements in the *application/_install* folder. - -5. Change the .htaccess file from -``` -RewriteBase /php-mvc-advanced/ -``` -to where you put this project, relative to the web root folder (usually /var/www). So when you put this project into -the web root, like directly in /var/www, then the line should look like or can be commented out: -``` -RewriteBase / -``` -If you have put the project into a sub-folder, then put the name of the sub-folder here: -``` -RewriteBase /sub-folder/ -``` - -6. Edit the *application/config/config.php*, change this line -```php -define('URL', 'http://127.0.0.1/php-mvc-advanced/'); -``` -to where your project is. Real domain, IP or 127.0.0.1 when developing locally. Make sure you put the sub-folder -in here (when installing in a sub-folder) too, also don't forget the trailing slash ! - -7. Edit the *application/config/config.php*, change these lines -```php -define('DB_TYPE', 'mysql'); -define('DB_HOST', '127.0.0.1'); -define('DB_NAME', 'php-mvc'); -define('DB_USER', 'root'); -define('DB_PASS', 'mysql'); -``` -to your database credentials. If you don't have an empty database, create one. Only change the type `mysql` if you -know what you are doing. - -8. Run `composer install` on the command line while being in the root of your project. - -## A quickstart tutorial - -You can also find these tutorial pictures in the *_tutorial* folder. -**Note:** **These files are not up-to-date, as Twig and SASS support are not mentioned here. I'll update the tutorial -when there's time.** - -![php-mvc introduction tutorial - page 1](_tutorial/tutorial-part-01.png) -![php-mvc introduction tutorial - page 2](_tutorial/tutorial-part-02.png) -![php-mvc introduction tutorial - page 3](_tutorial/tutorial-part-03.png) -![php-mvc introduction tutorial - page 4](_tutorial/tutorial-part-04.png) -![php-mvc introduction tutorial - page 5](_tutorial/tutorial-part-05.png) - -## You like what you see ? - -Then please also have a look on ... - -#### My other project php-login - -A collection of 4 similar login scripts for PHP, from a super-simple one-file -script with a SQLite one-file to a highly professional MVC frameworks solution. All scripts use the most advanced -hashing algorithms possible in PHP, exactly like the PHP core developers want you to use them. - -https://github.com/panique/php-login (full MVC framework) - -https://github.com/panique/php-login-minimal (minimal) - -https://github.com/panique/php-login-advanced (advanced) - -https://github.com/panique/php-login-one-file (one-file) - -#### My PHP and frontend blog - -Lots of non-boring development stuff and tutorials there. - -http://www.dev-metal.com - -## Useful information - -1. SQLite does not have a rowCount() method (!). Keep that in mind in case you use SQLite. - -2. Don't use the same name for class and method, as this might trigger an (unintended) *__construct* of the class. - This is really weird behaviour, but documented here: [php.net - Constructors and Destructors](http://php.net/manual/en/language.oop5.decon.php). - -## Add external libraries via Composer - -To add external libraries/tools/whatever into your project in an extremely clean way, simply add a line with the -repo name and version to the composer.json! Take a look on these tutorials if you want to get into Composer: -[How to install (and update) Composer on Windows 7 or Ubuntu / Debian](http://www.dev-metal.com/install-update-composer-windows-7-ubuntu-debian-centos/) -and [Getting started with Composer](http://www.dev-metal.com/getting-started-composer/). - -## License - -This project is licensed under the MIT License. -This means you can use and modify it for free in private or commercial projects. - -## Contribute - -Please commit into the develop branch (which holds the in-development version), not into master branch -(which holds the tested and stable version). - -## Support / Donate - -If you think this script is useful and saves you a lot of work, then think about supporting the project: - -1. Donate via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=P5YLUK4MW3LDG), [GitTip](https://www.gittip.com/Panique/) or [Flattr](https://flattr.com/submit/auto?user_id=panique&url=https%3A%2F%2Fgithub.com%2Fpanique%2Fphp-mvc-advanced). -2. Rent your next server at [A2 Hosting](http://www.a2hosting.com/4471.html) or [DigitalOcean](https://www.digitalocean.com/?refcode=40d978532a20). -3. Contribute to this project. Feel free to improve this project with your skills. -4. Spread the word: Tell others about this project. - -## Linked music tracks in the demo application - -The linked tracks in this naked application are just some of my personal favourites of the last few months. -I think it's always a good idea to fill boring nerd-code stuff with quality culture. +This will become the new home of MINI2, the advanced version of MINI (an extremely simple naked PHP application). \ No newline at end of file diff --git a/_tutorial/donate-with-flattr.png b/_tutorial/donate-with-flattr.png deleted file mode 100644 index 0241629..0000000 Binary files a/_tutorial/donate-with-flattr.png and /dev/null differ diff --git a/_tutorial/donate-with-paypal.png b/_tutorial/donate-with-paypal.png deleted file mode 100644 index 0d61aa5..0000000 Binary files a/_tutorial/donate-with-paypal.png and /dev/null differ diff --git a/_tutorial/tutorial-part-01.png b/_tutorial/tutorial-part-01.png deleted file mode 100644 index 795a3ad..0000000 Binary files a/_tutorial/tutorial-part-01.png and /dev/null differ diff --git a/_tutorial/tutorial-part-02.png b/_tutorial/tutorial-part-02.png deleted file mode 100644 index a8c0414..0000000 Binary files a/_tutorial/tutorial-part-02.png and /dev/null differ diff --git a/_tutorial/tutorial-part-03.png b/_tutorial/tutorial-part-03.png deleted file mode 100644 index 03ac95e..0000000 Binary files a/_tutorial/tutorial-part-03.png and /dev/null differ diff --git a/_tutorial/tutorial-part-04.png b/_tutorial/tutorial-part-04.png deleted file mode 100644 index 151c0e5..0000000 Binary files a/_tutorial/tutorial-part-04.png and /dev/null differ diff --git a/_tutorial/tutorial-part-05.png b/_tutorial/tutorial-part-05.png deleted file mode 100644 index 64cbf50..0000000 Binary files a/_tutorial/tutorial-part-05.png and /dev/null differ diff --git a/application/.htaccess b/application/.htaccess deleted file mode 100644 index f68fbbe..0000000 --- a/application/.htaccess +++ /dev/null @@ -1,4 +0,0 @@ - - Order Deny,Allow - Deny from all - diff --git a/application/_install/01-create-database.sql b/application/_install/01-create-database.sql deleted file mode 100644 index 53c2d0b..0000000 --- a/application/_install/01-create-database.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE DATABASE IF NOT EXISTS `php-mvc`; diff --git a/application/_install/02-create-table-song.sql b/application/_install/02-create-table-song.sql deleted file mode 100644 index 4b68979..0000000 --- a/application/_install/02-create-table-song.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE `php-mvc`.`song` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `artist` text COLLATE utf8_unicode_ci NOT NULL, - `track` text COLLATE utf8_unicode_ci NOT NULL, - `link` text COLLATE utf8_unicode_ci, - PRIMARY KEY (`id`), - UNIQUE KEY `id` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/application/_install/03-insert-demo-data-into-table-song.sql b/application/_install/03-insert-demo-data-into-table-song.sql deleted file mode 100644 index 5104651..0000000 --- a/application/_install/03-insert-demo-data-into-table-song.sql +++ /dev/null @@ -1,31 +0,0 @@ -INSERT INTO `php-mvc`.`song` (`id`, `artist`, `track`, `link`) VALUES -(1, 'Dena', 'Cash, Diamond Ring, Swimming Pools', 'http://www.youtube.com/watch?v=r4CDc9yCAqE'), -(2, 'Jessy Lanza', 'Kathy Lee', 'http://vimeo.com/73455369'), -(3, 'The Orwells', 'In my Bed (live)', 'http://www.youtube.com/watch?v=8tA_2qCGnmE'), -(4, 'L''Orange & Stik Figa', 'Smoke Rings', 'https://www.youtube.com/watch?v=Q5teohMyGEY'), -(5, 'Labyrinth Ear', 'Navy Light', 'http://www.youtube.com/watch?v=a9qKkG7NDu0'), -(6, 'Bon Hiver', 'Wolves (Kill them with Colour Remix)', 'http://www.youtube.com/watch?v=5GXAL5mzmyw'), -(7, 'Detachments', 'Circles (Martyn Remix)', 'http://www.youtube.com/watch?v=UzS7Gvn7jJ0'), -(8, 'Dillon & Dirk von Loetzow', 'Tip Tapping (Live at ZDF Aufnahmezustand)', 'https://www.youtube.com/watch?v=hbrOLsgu000'), -(9, 'Dillon', 'Contact Us (Live at ZDF Aufnahmezustand)', 'https://www.youtube.com/watch?v=E6WqTL2Up3Y'), -(10, 'Tricky', 'Hey Love (Promo Edit)', 'http://www.youtube.com/watch?v=OIsCGdW49OQ'), -(11, 'Compuphonic', 'Sunset feat. Marques Toliver (DJ T. Remix)', 'http://www.youtube.com/watch?v=Ue5ZWSK9r00'), -(12, 'Ludovico Einaudi', 'Divenire (live @ Royal Albert Hall London)', 'http://www.youtube.com/watch?v=X1DRDcGlSsE'), -(13, 'Maxxi Soundsystem', 'Regrets we have no use for (Radio1 Rip)', 'https://soundcloud.com/maxxisoundsystem/maxxi-soundsystem-ft-name-one'), -(14, 'Beirut', 'Nantes (Fredo & Thang Remix)', 'https://www.youtube.com/watch?v=ojV3oMAgGgU'), -(15, 'Buku', 'All Deez', 'http://www.youtube.com/watch?v=R0bN9JRIqig'), -(16, 'Pilocka Krach', 'Wild Pete', 'http://www.youtube.com/watch?v=4wChP_BEJ4s'), -(17, 'Mount Kimbie', 'Here to stray (live at Pitchfork Music Festival Paris)', 'http://www.youtube.com/watch?v=jecgI-zEgIg'), -(18, 'Kool Savas', 'King of Rap (2012) / Ein Wunder', 'http://www.youtube.com/watch?v=mTqc6UTG1eY&hd=1'), -(19, 'Chaim feat. Meital De Razon', 'Love Rehab (Original Mix)', 'http://www.youtube.com/watch?v=MJT1BbNFiGs'), -(20, 'Emika', 'Searching', 'http://www.youtube.com/watch?v=oscuSiHfbwo'), -(21, 'Emika', 'Sing to me', 'http://www.youtube.com/watch?v=k9sDBZm8pgk'), -(22, 'George Fitzgerald', 'Thinking of You', 'http://www.youtube.com/watch?v=-14B8l49iKA'), -(23, 'Disclosure', 'You & Me (Flume Edit)', 'http://www.youtube.com/watch?v=OUkkaqSNduU'), -(24, 'Crystal Castles', 'Doe Deer', 'http://www.youtube.com/watch?v=zop0sWrKJnQ'), -(25, 'Tok Tok vs. Soffy O.', 'Missy Queens Gonna Die', 'http://www.youtube.com/watch?v=EN0Tnw5zy6w'), -(26, 'Fink', 'Maker (Synapson Remix)', 'http://www.youtube.com/watch?v=Dyd-cUkj4Nk'), -(27, 'Flight Facilities (ft. Christine Hoberg)', 'Clair De Lune', 'http://www.youtube.com/watch?v=Jcu1AHaTchM'), -(28, 'Karmon', 'Turning Point (Original Mix)', 'https://www.youtube.com/watch?v=-tB-zyLSPEo'), -(29, 'Shuttle Life', 'The Birds', 'http://www.youtube.com/watch?v=-I3m3cWDEtM'), -(30, 'Santé', 'Homegirl (Rampa Mix)', 'http://www.youtube.com/watch?v=fnhMNOWxLYw'); diff --git a/application/config/config.php b/application/config/config.php deleted file mode 100644 index 27a2314..0000000 --- a/application/config/config.php +++ /dev/null @@ -1,40 +0,0 @@ -render('home/index'); - } - - /** - * PAGE: exampleone - * This method handles what happens when you move to http://yourproject/home/exampleone - * The camelCase writing is just for better readability. The method name is case insensitive. - */ - public function exampleOne() - { - $this->render('home/example_one'); - } - - /** - * PAGE: exampletwo - * This method handles what happens when you move to http://yourproject/home/exampletwo - * The camelCase writing is just for better readability. The method name is case insensitive. - */ - public function exampleTwo() - { - $this->render('home/example_two'); - } -} diff --git a/application/controller/songs.php b/application/controller/songs.php deleted file mode 100644 index 090d647..0000000 --- a/application/controller/songs.php +++ /dev/null @@ -1,76 +0,0 @@ -loadModel('SongsModel'); - $songs = $songs_model->getAllSongs(); - - // load another model, perform an action, pass the returned data to a variable - // NOTE: please write the name of the model "LikeThis" - $stats_model = $this->loadModel('StatsModel'); - $amount_of_songs = $stats_model->getAmountOfSongs(); - - // render the view, pass the data - $this->render('songs/index', array('songs' => $songs, 'amount_of_songs' => $amount_of_songs)); - } - - /** - * ACTION: addSong - * This method handles what happens when you move to http://yourproject/songs/addsong - * IMPORTANT: This is not a normal page, it's an ACTION. This is where the "add a song" form on songs/index - * directs the user after the form submit. This method handles all the POST data from the form and then redirects - * the user back to songs/index via the last line: header(...) - * This is an example of how to handle a POST request. - */ - public function addSong() - { - // if we have POST data to create a new song entry - if (isset($_POST["submit_add_song"])) { - // load model, perform an action on the model - $songs_model = $this->loadModel('SongsModel'); - $songs_model->addSong($_POST["artist"], $_POST["track"], $_POST["link"]); - } - - // where to go after song has been added - header('location: ' . URL . 'songs/index'); - } - - /** - * ACTION: deleteSong - * This method handles what happens when you move to http://yourproject/songs/deletesong - * IMPORTANT: This is not a normal page, it's an ACTION. This is where the "delete a song" button on songs/index - * directs the user after the click. This method handles all the data from the GET request (in the URL!) and then - * redirects the user back to songs/index via the last line: header(...) - * This is an example of how to handle a GET request. - * @param int $song_id Id of the to-delete song - */ - public function deleteSong($song_id) - { - // if we have an id of a song that should be deleted - if (isset($song_id)) { - // load model, perform an action on the model - $songs_model = $this->loadModel('SongsModel'); - $songs_model->deleteSong($song_id); - } - - // where to go after song has been deleted - header('location: ' . URL . 'songs/index'); - } -} diff --git a/application/libs/application.php b/application/libs/application.php deleted file mode 100644 index d52678c..0000000 --- a/application/libs/application.php +++ /dev/null @@ -1,95 +0,0 @@ -splitUrl(); - - // check for controller: does such a controller exist ? - if (file_exists('./application/controller/' . $this->url_controller . '.php')) { - - // if so, then load this file and create this controller - // example: if controller would be "car", then this line would translate into: $this->car = new car(); - require './application/controller/' . $this->url_controller . '.php'; - $this->url_controller = new $this->url_controller(); - - // check for method: does such a method exist in the controller ? - if (method_exists($this->url_controller, $this->url_action)) { - - // call the method and pass the arguments to it - if (isset($this->url_parameter_3)) { - // will translate to something like $this->home->method($param_1, $param_2, $param_3); - $this->url_controller->{$this->url_action}($this->url_parameter_1, $this->url_parameter_2, $this->url_parameter_3); - } elseif (isset($this->url_parameter_2)) { - // will translate to something like $this->home->method($param_1, $param_2); - $this->url_controller->{$this->url_action}($this->url_parameter_1, $this->url_parameter_2); - } elseif (isset($this->url_parameter_1)) { - // will translate to something like $this->home->method($param_1); - $this->url_controller->{$this->url_action}($this->url_parameter_1); - } else { - // if no parameters given, just call the method without parameters, like $this->home->method(); - $this->url_controller->{$this->url_action}(); - } - } else { - // default/fallback: call the index() method of a selected controller - $this->url_controller->index(); - } - } else { - // invalid URL, so simply show home/index - require './application/controller/home.php'; - $home = new Home(); - $home->index(); - } - } - - /** - * Get and split the URL - */ - private function splitUrl() - { - if (isset($_GET['url'])) { - - // split URL - $url = rtrim($_GET['url'], '/'); - $url = filter_var($url, FILTER_SANITIZE_URL); - $url = explode('/', $url); - - // Put URL parts into according properties - // By the way, the syntax here is just a short form of if/else, called "Ternary Operators" - // @see http://davidwalsh.name/php-shorthand-if-else-ternary-operators - $this->url_controller = (isset($url[0]) ? $url[0] : null); - $this->url_action = (isset($url[1]) ? $url[1] : null); - $this->url_parameter_1 = (isset($url[2]) ? $url[2] : null); - $this->url_parameter_2 = (isset($url[3]) ? $url[3] : null); - $this->url_parameter_3 = (isset($url[4]) ? $url[4] : null); - - // for debugging. uncomment this if you have problems with the URL - // echo 'Controller: ' . $this->url_controller . '
'; - // echo 'Action: ' . $this->url_action . '
'; - // echo 'Parameter 1: ' . $this->url_parameter_1 . '
'; - // echo 'Parameter 2: ' . $this->url_parameter_2 . '
'; - // echo 'Parameter 3: ' . $this->url_parameter_3 . '
'; - } - } -} diff --git a/application/libs/controller.php b/application/libs/controller.php deleted file mode 100644 index c4275ce..0000000 --- a/application/libs/controller.php +++ /dev/null @@ -1,63 +0,0 @@ -openDatabaseConnection(); - } - - /** - * Open the database connection with the credentials from application/config/config.php - */ - private function openDatabaseConnection() - { - // set the (optional) options of the PDO connection. in this case, we set the fetch mode to - // "objects", which means all results will be objects, like this: $result->user_name ! - // 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); - - // 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, DB_USER, DB_PASS, $options); - } - - /** - * Load the model with the given name. - * loadModel("SongModel") would include models/songmodel.php and create the object in the controller, like this: - * $songs_model = $this->loadModel('SongsModel'); - * Note that the model class name is written in "CamelCase", the model's filename is the same in lowercase letters - * @param string $model_name The name of the model - * @return object model - */ - public function loadModel($model_name) - { - require 'application/models/' . strtolower($model_name) . '.php'; - // return new model (and pass the database connection to the model) - return new $model_name($this->db); - } - - public function render($view, $data_array = array()) - { - // load Twig, the template engine - // @see http://twig.sensiolabs.org - $twig_loader = new Twig_Loader_Filesystem(PATH_VIEWS); - $twig = new Twig_Environment($twig_loader); - - // render a view while passing the to-be-rendered data - echo $twig->render($view . PATH_VIEW_FILE_TYPE, $data_array); - } -} diff --git a/application/models/songsmodel.php b/application/models/songsmodel.php deleted file mode 100644 index 52ebfd0..0000000 --- a/application/models/songsmodel.php +++ /dev/null @@ -1,63 +0,0 @@ -db = $db; - } catch (PDOException $e) { - exit('Database connection could not be established.'); - } - } - - /** - * Get all songs from database - */ - public function getAllSongs() - { - $sql = "SELECT id, artist, track, link FROM song"; - $query = $this->db->prepare($sql); - $query->execute(); - - // fetchAll() is the PDO method that gets all result rows, here in object-style because we defined this in - // libs/controller.php! If you prefer to get an associative array as the result, then do - // $query->fetchAll(PDO::FETCH_ASSOC); or change libs/controller.php's PDO options to - // $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ... - return $query->fetchAll(); - } - - /** - * Add a song to database - * @param string $artist Artist - * @param string $track Track - * @param string $link Link - */ - public function addSong($artist, $track, $link) - { - // clean the input from javascript code for example - $artist = strip_tags($artist); - $track = strip_tags($track); - $link = strip_tags($link); - - $sql = "INSERT INTO song (artist, track, link) VALUES (:artist, :track, :link)"; - $query = $this->db->prepare($sql); - $query->execute(array(':artist' => $artist, ':track' => $track, ':link' => $link)); - } - - /** - * Delete a song in the database - * Please note: this is just an example! In a real application you would not simply let everybody - * add/update/delete stuff! - * @param int $song_id Id of song - */ - public function deleteSong($song_id) - { - $sql = "DELETE FROM song WHERE id = :song_id"; - $query = $this->db->prepare($sql); - $query->execute(array(':song_id' => $song_id)); - } -} diff --git a/application/models/statsmodel.php b/application/models/statsmodel.php deleted file mode 100644 index 2d197e2..0000000 --- a/application/models/statsmodel.php +++ /dev/null @@ -1,30 +0,0 @@ -db = $db; - } catch (PDOException $e) { - exit('Database connection could not be established.'); - } - } - - /** - * Get simple "stats". This is just a simple demo to show - * how to use more than one model in a controller (see application/controller/songs.php for more) - */ - public function getAmountOfSongs() - { - $sql = "SELECT COUNT(id) AS amount_of_songs FROM song"; - $query = $this->db->prepare($sql); - $query->execute(); - - // fetchAll() is the PDO method that gets all result rows - return $query->fetch()->amount_of_songs; - } -} diff --git a/application/views/_templates/base.twig b/application/views/_templates/base.twig deleted file mode 100644 index 3c68aab..0000000 --- a/application/views/_templates/base.twig +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - PHP MVC skeleton - - - - - - - - - - - -
- -
- Everything in this box is loaded from application/views/_templates/header.php ! -
- The green line is added via JavaScript (to show how to integrate JavaScript). -
-

The header (used on all pages)

- -

Demo image, to show usage of public/img folder

-
- -
- -

Demo Navigation

- - - -

Demo JavaScript

-
-
-
- - - {% block content %} {% endblock %} - - - \ No newline at end of file diff --git a/application/views/home/example_one.twig b/application/views/home/example_one.twig deleted file mode 100644 index 332c58c..0000000 --- a/application/views/home/example_one.twig +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "_templates/base.twig" %} -{% block content %} -
-

You are in the View: application/views/home/example_one.php (everything in the box comes from this file)

-

In a real application this could be a normal page.

-
-{% endblock %} diff --git a/application/views/home/example_two.twig b/application/views/home/example_two.twig deleted file mode 100644 index 6edf4fc..0000000 --- a/application/views/home/example_two.twig +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "_templates/base.twig" %} -{% block content %} -
-

You are in the View: application/views/home/example_two.php (everything in the box comes from this file)

-

In a real application this could be a normal page.

-
-{% endblock %} diff --git a/application/views/home/index.twig b/application/views/home/index.twig deleted file mode 100644 index a065869..0000000 --- a/application/views/home/index.twig +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "_templates/base.twig" %} -{% block content %} -
-

You are in the View: application/views/home/index.php (everything in the box comes from this file)

-

In a real application this could be the homepage.

-
-{% endblock %} diff --git a/application/views/songs/index.twig b/application/views/songs/index.twig deleted file mode 100644 index 56c3ca8..0000000 --- a/application/views/songs/index.twig +++ /dev/null @@ -1,55 +0,0 @@ -{% extends "_templates/base.twig" %} -{% block content %} -
-

You are in the View: application/views/song/index.php (everything in this box comes from that file)

- -
-

Add a song

-
- - - - - - - -
-
- -
-

Amount of songs (data from second model)

-
- {{ amount_of_songs }} -
-

List of songs (data from first model)

- - - - - - - - - - - - {% for song in songs %} - - - - - - - - {% endfor %} - -
IdArtistTrackLinkDELETE
{{ song.id }}{{ song.artist }}{{ song.track }} - {% if song.link %} - {{ song.link }} - {% endif %} - - x -
-
-
-{% endblock %} \ No newline at end of file diff --git a/composer.json b/composer.json deleted file mode 100644 index 252395b..0000000 --- a/composer.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "panique/php-mvc-advanced", - "type": "project", - "description": "A simple PHP MVC boilerplate - Advanced version", - "keywords": ["mvc", "skeleton", "boilerplate", "naked", "barebone", "application"], - "homepage": "https://github.com/panique/php-mvc-advanced", - "license": "MIT", - "authors": [ - { - "name": "Panique", - "homepage": "http://careers.stackoverflow.com/panique", - "role": "Developer" - } - ], - "support": { - "issues": "https://github.com/panique/php-mvc-advanced/issues", - "source": "https://github.com/panique/php-mvc-advanced" - }, - "require": { - "php": ">=5.3.0", - "twig/twig": "1.*" - }, - "require-dev": { - "panique/laravel-sass": "dev-master" - } -} \ No newline at end of file diff --git a/index.php b/index.php deleted file mode 100644 index 4b7787d..0000000 --- a/index.php +++ /dev/null @@ -1,30 +0,0 @@ -