Object-oriented PHP building-blocks for websites and webapps.
StatelessCMS is a headless PHP framework designed for creating database-driven PHP applications, "headless" meaning there is no existing front-end. StatelessCMS isn't an app or a CMS itself - it just gives you the building blocks to create one yourself.
Get a server running PHP 7.0 and a SQL database. Note that apache is recommended, as Request::getHeaders() and Request::getToken() rely on apache_get_headers() as of v0.0.3
The easiest way to install StatelessCMS is to install with Composer:
composer require stateless/cms
Download the latest release from https://github.com/StatelessSoftware/StatelessCMS/releases.
If you would like the live development branch instead, download or clone from github. https://github.com/StatelessSoftware/StatelessCMS.git
Although you are free to use any directory structure you choose, the common basic structure for StatelessCMS is as follows. Don't worry too much about the specifics - we'll create each part step by step.
|- app
|- Controller
|- Form
|- FormInput
|- Layout
|- Menu
|- Model
|- View
|- app.php
|- functions.php
|- conf
|- app.conf.php
|- public
|- css
|- js
|- .htaccess
|- index.php
|- vendor
|- stateless
If you didn't already, install StatelessCMS to vendor/stateless (follow installation instructions above)
Open public/index.php. Insert the following code:
<?php
namespace Stateless;
require_once("../vendor/autoload.php");
echo "Home";
If you downloaded and installed StatelessCMS without using Composer, change ../vendor/autoload.php to your StatelessCMS.php file
This file is the entry point, meaning it is the start of the program. For now, we will use it to show our examples. Later, we can use it to startup our application.
Open a browser and navigate to localhost/public/ You should see Home.
Ensure your httpd document root is set to public/ Now navigate to localhost/ and you should see Home
- In a directory block for
public
, setAllowOverride All
- Copy the following htaccess file to public/.htaccess
You may need to install mod_rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Now we will create additional pages with clean urls. Replace index.php
with the following code
<?php
namespace Stateless;
require_once("../vendor/autoload.php");
switch (Request::getPath()) {
case "/":
echo "Home";
break;
case "/about":
echo "Read all about us!";
break;
case "/contact":
echo "Contact us.";
break;
default:
Response::header(404);
echo "Page not found.";
break;
}
Load up localhost/about
in your browser, you should see "Read all about us!"