Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Just an extremely simple naked PHP application, useful for small projects and quick prototypes. Some might call it a micro framework :)

NotificationsYou must be signed in to change notification settings

panique/mini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MINI - A naked barebone PHP application

MINI

MINI is an extremely simple and easy to understand skeleton PHP application, reduced to the max.MINI is NOT a professional framework and it does not come with all the stuff real frameworks have.If you just want to show some pages, do a few database calls and a little-bit of AJAX here and there, withoutreading in massive documentations of highly complex professional frameworks, then MINI might be very useful for you.MINI is easy to install, runs nearly everywhere and doesn't make things more complicated than necessary.

For a deeper introduction into MINI have a look into this blog post:MINI, an extremely simple barebone PHP application.

Features

  • extremely simple, easy to understand
  • simple but clean structure
  • makes "beautiful" clean URLs
  • demo CRUD actions: Create, Read, Update and Delete database entries easily
  • demo AJAX call
  • tries to follow PSR 1/2 coding guidelines
  • uses PDO for any database requests, comes with an additional PDO debug tool to emulate your SQL statements
  • commented code
  • uses only native PHP code, so people don't have to learn a framework

Forks of MINI

TINY

MINI has a smaller brother, namedTINY. It's similar to MINI, but runs withoutmod_rewrite in nearly every environment. Not suitable for live sites, but nice for quick prototyping.

MINI2

MINI also has a bigger brother, namedMINI2. It's even simpler, has been builtusing Slim and has nice features like SASS-compiling, Twig etc.

MINI3

MINI3 it the successor of MINI,using the original MINI1 native application structure (without Slimunder the hood), but with proper PSR-4 autoloading, multiple modelclasses and real namespaces.

Requirements

  • PHP 5.3.0+ (when first released), now it works fine with current stable versions PHP 5.6 and 7.1, 7.2., 7.3 and 7.4.The latest PHP 8.0 is not tested yet but should also work fine.
  • MySQL
  • mod_rewrite activated (tutorials below, but there's alsoTINY, a mod_rewrite-lessversion of MINI)

Installation (in Vagrant, 100% automatic)

If you are using Vagrant for your development, then you can install MINI with one click (or one command on thecommand line) [Vagrant doc]. MINI comes with a demoVagrant-file (defines your Vagrant box) and a demo bootstrap.sh which automatically installs Apache, PHP, MySQL,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 GitHuband runs the demo SQL statements (for demo data). This is 100% automatic, you'll end up after +/- 5 minutes with a fullyrunning installation of MINI2 inside an Ubuntu 14.04 LTS Vagrant box.

To do so, putVagrantfile andbootstrap.sh from_vagrant inside a folder (and nothing else).Dovagrant box add ubuntu/focal64 to add Ubuntu 20.04 LTS 64bit to Vagrant (unless you already haveit), then dovagrant up to run the box. When installation is finished you can directly use the fully installed demoapp on192.168.33.44 (you can change this in the Vagrantfile). As this just a quick demo environment the MySQLroot password and the PHPMyAdmin root password are set to12345678, the project is installed in/var/www/html/myproject.You can change this for sure insidebootstrap.sh. Shut down the box withvagrant halt

Auto-Installation on Ubuntu 14.04 LTS (in 30 seconds)

You can install MINI including Apache, MySQL, PHP and PHPMyAdmin, mod_rewrite, Composer, all necessary settings andeven the passwords inside the configs file by simply downloading one file and executing it, the entire installationwill run 100% automatically. Find the tutorial in this blog article:Install MINI in 30 seconds inside Ubuntu 14.04 LTS

Installation

  1. Edit the database credentials inapplication/config/config.php
  2. Execute the .sql statements in the_install/-folder (with PHPMyAdmin for example).
  3. Make sure you have mod_rewrite activated on your server / in your environment. Some guidelines:Ubuntu 14.04 LTS,Ubuntu 12.04 LTS,EasyPHP on Windows,AMPPS on Windows/Mac OS,XAMPP for Windows,MAMP on Mac OS

MINI runs without any further configuration. You can also put it inside a sub-folder, it will work without anyfurther configuration.Maybe useful: A simple tutorial onHow to install LAMPP (Linux, Apache, MySQL, PHP, PHPMyAdmin) on Ubuntu 14.04 LTSandthe same for Ubuntu 12.04 LTS.

Server configs for

nginx

server{server_name default_server _;   # Listen to any servernamelisten      [::]:80;listen80;root /var/www/html/myproject/public;location /{indexindex.php;try_files /$uri /$uri/ /index.php?url=$uri;}location~\.(php)${fastcgi_pass   unix:/var/run/php5-fpm.sock;fastcgi_indexindex.php;fastcgi_param  SCRIPT_FILENAME$document_root$fastcgi_script_name;include fastcgi_params;}}

A deeper discussion on nginx setups can be foundhere.

Security

The script makes use of mod_rewrite and blocks all access to everything outside the /public folder.Your .git folder/files, operating system temp files, the application-folder and everything else is not accessible(when set up correctly). For database requests PDO is used, so no need to think about SQL injection (unless youare using extremely outdated MySQL versions).

Goodies

MINI comes with a little customizedPDO debugger tool (find the code inapplication/libs/helper.php), trying to emulate your PDO-SQL statements. It's extremely easy to use:

$sql ="SELECT id, artist, track, link FROM song WHERE id = :song_id LIMIT 1";$query =$this->db->prepare($sql);$parameters =array(':song_id' =>$song_id);echo Helper::debugPDO($sql,$parameters);$query->execute($parameters);

Why has the "Error" class been renamed to "Problem"?

The project was written in PHP5 times, but with the release of PHP7 it's not possible anymore to name a class"Error" as PHP itself has a internal Error class now. Renaming was the most simple solution, compared to otheroptions like "ErrorController" etc. which would add new problems like uppercase filenames etc. (which will notwork properly on some setups).

License

This project is licensed under the MIT License.This means you can use and modify it for free in private or commercial projects.

My blog

And by the way, I'm also blogging atDev Metal.

Quick-Start

The structure in general

The application's URL-path translates directly to the controllers (=files) and their methods insideapplication/controllers.

example.com/home/exampleOne will do what theexampleOne() method in application/controllers/home.php says.

example.com/home will do what theindex() method in application/controllers/home.php says.

example.com will do what theindex() method in application/controllers/home.php says (default fallback).

example.com/songs will do what theindex() method in application/controllers/songs.php says.

example.com/songs/editsong/17 will do what theeditsong() method in application/controllers/songs.php says andwill pass17 as a parameter to it.

Self-explaining, right ?

Showing a view

Let's look at the exampleOne()-method in the home-controller (application/controllers/home.php): This simply showsthe header, footer and the example_one.php page (in views/home/). By intention as simple and native as possible.

publicfunctionexampleOne(){// load viewrequireAPP .'views/_templates/header.php';requireAPP .'views/home/example_one.php';requireAPP .'views/_templates/footer.php';}

Working with data

Let's look into the index()-method in the songs-controller (application/controllers/songs.php): Similar to exampleOne,but here we also request data. Again, everything is extremely reduced and simple: $this->model->getAllSongs() simplycalls the getAllSongs()-method in application/model/model.php.

publicfunctionindex(){// getting all songs and amount of songs$songs =$this->model->getAllSongs();$amount_of_songs =$this->model->getAmountOfSongs();// load view. within the view files we can echo out $songs and $amount_of_songs easilyrequireAPP .'views/_templates/header.php';requireAPP .'views/songs/index.php';requireAPP .'views/_templates/footer.php';}

For extreme simplicity, all data-handling methods are in application/model/model.php. This is for sure not reallyprofessional, but the most simple implementation. Have a look how getAllSongs() in model.php looks like: Pure andsuper-simple PDO.

publicfunctiongetAllSongs(){$sql ="SELECT id, artist, track, link FROM song";$query =$this->db->prepare($sql);$query->execute();return$query->fetchAll();}

The result, here $songs, can then easily be used directlyinside the view files (in this case application/views/songs/index.php, in a simplified example):

<tbody><?phpforeach ($songsas$song) {?>    <tr>        <td><?phpif (isset($song->artist))echohtmlspecialchars($song->artist,ENT_QUOTES,'UTF-8');?></td>        <td><?phpif (isset($song->track))echohtmlspecialchars($song->track,ENT_QUOTES,'UTF-8');?></td>    </tr><?php }?></tbody>

History

MINI is the successor of php-mvc. As php-mvc didn't provide a real MVC structure (and several people complainedabout that - which is totally right!) I've renamed and rebuild the project.

Dear haters, trolls and everything-sucks-people...

... MINI is just a simple helper-tool I've created for my daily work, simply because it was much easier to setup and tohandle than real frameworks. For daily agency work, quick prototyping and frontend-driven projects it's totally okay,does the job and there's absolutely no reason to discuss why it's "shit compared to Laravel", why it does not followseveral MVC principles or why there's no personal unpaid support or no russian translation or similar weird stuff.The trolling against Open-Source-projects (and their authors) has really reached insane dimensions.

I've written this unpaid, voluntarily, in my free-time and uploaded it on GitHub to share.It's totally free, for private and commercial use. If you don't like it, don't use it.If you see issues, then please write a ticket (and if you are really cool: I'm very thankful for any commits!).But don't bash, don't complain, don't hate. Only bad people do so.

Contribute

Please commit into the develop branch (which holds the in-development version), not into master branch(which holds the tested and stable version).

Changelog

December 2002

  • [panique] updated Vagrant installer to run with PHP 7.4 and Ubuntu 20.04

August 2016

  • [codebicycle/panique] renamed Error class to Problem to make it PHP7 compatible #209
  • [ynohtna92/panique] URL protocol is now protocol-independent #208

February 2015

  • [jeroenseegers] nginx setup configuration

December 2014

  • [panique] css fixes
  • [panique] renamed controller / view to singular
  • [panique] added charset to PDO creation (increased security)

November 2014

  • [panique] auto-install script for Vagrant
  • [panique] basic documentation
  • [panique] PDO-debugger is now a static helper-method, not a global function anymore
  • [panique] folder renaming
  • [reg4in] JS AJAX calls runs now properly even when using script in sub-folder
  • [panique] removed all "models", using one model file now
  • [panique] full project renaming, re-branding

October 2014

  • [tarcnux/panique] PDO debugging
  • [panique] demo ajax call
  • [panique] better output escaping
  • [panique] renamed /libs to /core
  • [tarcnux] basic CRUD (create/read/update/delete) examples have now an U (update)
  • [panique] URL is now config-free, application detects URL and sub-folder
  • [elysdir] htaccess has some good explanation-comments now
  • [bst27] fallback for non-existing controller / method
  • [panique] fallback will show error-page now
  • [digitaltoast] URL split fix to make php-mvc work flawlessly on nginx
  • [AD7six] security improvement: moved index.php to /public, route ALL request to /public

September 2014

  • [panique] added link to support forum
  • [panique] added link to Facebook page

August 2014

  • [panique] several changes in the README, donate-button changes

June 2014

  • [digitaltoast] removed X-UA-Compatible meta tag from header (as it's not needed anymore these days)
  • [digitaltoast] removed protocol in jQuery URL (modern way to load external files, making it independent to protocol change)
  • [digitaltoast] downgraded jQuery from 2.1 to 1.11 to avoid problems when working with IE7/8 (jQuery 2 dropped IE7/8 support)
  • [panique] moved jQuery loading to footer (to avoid page render blocking)

April 2014

  • [panique] updated jQuery link to 2.1
  • [panique] more than 3 parameters (arguments to be concrete) are possible
  • [panique] cleaner way of parameter handling
  • [panique] smaller cleanings and improvements
  • [panique] Apache 2.4 install information

January 2014

  • [panique] fixed .htaccess issue when there's a controller named "index" and a base index.php (which collide)

Support the project

Support the project by renting a server atDigitalOcean or just tipping a coffee at BuyMeACoffee.com. Thanks! :)

Buy Me A Coffee

About

Just an extremely simple naked PHP application, useful for small projects and quick prototypes. Some might call it a micro framework :)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors11


[8]ページ先頭

©2009-2025 Movatter.jp