jacob-roth/simple-framework

SimpleFramework is a simple framework for building out html\php pages

v1.3.1 2024-09-08 03:55 UTC

This package is auto-updated.

Last update: 2024-10-08 04:16:39 UTC


README

SimpleFramework is a simple framework for building out php pages

composer require jacob-roth/simple-framework

So J, what does this do?

Ever want to build a static website and want to reuse code you made? No? What do you mean no one builds static sites anymore? Well, SimpleFramework lets you do this anyway.

What's that? Other packages do this better? That's probably true. You should use them, then.

What SimpleFramework does:

  • URL Routing
    • maps requests to pages directory
      • ex: requesting /page1 delivers /pages/page1.php
      • ex: requesting /creative/page1 delivers /pages/creative/page1.php
    • still works for assets
      • ex: requesting /assets/styles.css delivers /assets/styles.css
  • Build Pages
    • PHP pages in the pages directory
    • Use Components
  • Build Components
    • PHP or HTML files in the components directory
    • Components can be reused between pages
    • Can pass parameters through $data object to and between components

What You Need To Do

  1. composer require jacob-roth/simple-framework

  2. Create /pages and /components directories in project root

  3. Add the following to .htaccess into project root directory

    RewriteEngine On
    RewriteRule ^(.*)$ index.php [NC,L,QSA]
  4. Create index.php in project root directory

  5. Add the following to index.php

    SimpleFramework\Constants::setDefaults();
    SimpleFramework\Util::loadContent();

Using Util

ENVs

If needed, you can change some of the defaults in SimpleFramework using $_ENV

You can set these ENVs like this:

$_ENV[SimpleFramework\Constants::notFoundFile] = __DIR__ . "/pages/404.php";

This must be done after calling Constants::setDefaults()

Limitations

  • If you choose to change the ENV variable APP_SF_APACHE_MIME_DOT_TYPES, you must run the following to properly create the type mapping
SimpleFramework\Constants::setMimeTypesMap();