OneFileFramework is a complete MVC-capable framework encapsulated in a single PHP-file!

Dynamic usage

This is really where OFF shines. It gives you the power of bloated frameworks in one percent of the size. ;)


You make your controllers in /controllers. These are called for any given pagename if they exist. So an access to index.php?p=blog would cause the controller controllers/blog.php to be called. For anyone new to MVC, this is where any actual logic should be done. Update your database, do your calculations and so on. Form data is recommended to be sent as POST data, but there is nothing preventing you from adding more GET variables to the URL string.

There are several "global" variables (listed below), and one of these, $p contains the current pagename. If your controller wants to affect what gets shown to the user when the controller is done, all you have to do is change $p to another "pagename" and the view for that page will be used instead.

Controllers are run using PHP's include statement, and should therefore be encapsulated in <?php and ?>.


Views are stored in /views and are the files that generates your output. They are in theory normal PHP files, and all the "global" variables and any variables generated by the controller will be available from any PHP tags in your view.


The wireframes are stored in /wireframes and are the "master templates" for your site. Normally, one would be enough. This is the PHP file that sets up your webpages and contains all common elements for your site, like a logo and a menu. The only "special" thing about your wireframe is that it contains the PHP tag <?php include 'views/'.$p.'.php'; ?> where you want the current view to appear. The name of the current wireframe is stored in the "global" variable $w and might be changed by the controller if you want to output some pages (or files) with different wireframes.

Including other stuff

Since everything in an OFF site runs from index.php, you can include all you want from the root path of your installation. I would personally recommend making a subdir, like /libs and drop any 3rd party libraries you want in there. That way, if you wanted to include a library called suckerpunch from there, all you had to do was include "libs/suckerpunch/suckerpunch.php";.

I also recommend the same thing for js and graphics. Make a css and a js subdirectory on the root of your installation and just include them with relative paths as you would from any HTML file in the root of your installation. I.e "css/main.css" or "js/fancystuff.js". This would make for a really nice and clean directory tree.

Global variables

The "global" variables (mind the quotes) mentioned on this page aren't global in the programming language sense of the word, but variables that are always in the scope of wireframes, views and controllers when they are included. These variables are actually your only mean of communicating with OFF and are as follows:


If there is a file called "global.php" in the root dir of your OFF installation, it will be included before any controllers. This lets you set up any functions that should be globally available for all your controllers and/or views.


It is possible to use subdirectories for pagenames. Just use pagetitles like "dirname/pagename" and the controller will be accessed like "controllers/dirname/pagename.php" and the view like "views/dirname/pagename.php".


OFF contains no protection against direct access to your controllers and view. Please consider yourself wether or not parts of your code needs this. The easiest way is probably to check the $p variable for the correct content.