Humblee

A humble PHP framework & CMS

Structure and Routing

Folder structure

Humblee's root folder structure consist of the following folders:

  1. ~/application the bulk of all custom functionality developed for your app should live in the MVC structured subfolders of this directory, including custom controllers, models and template views.
  2. ~/humblee consist of the core files of the Humblee framework and it's integrated CMS. With the exception of your configuration environment files, you should not need to modify anything in this folder.
  3. ~/public is the only folder that can be read by navigable links; from the browser's perspective, this is the root of the Humblee application. This folder has sub-folders for both Humblee's UI components and for your application to include all of the javascript, CSS and additional assets needed for the client-side development of your site.
  4. ~/storage is used primarily by the "media manager" tool within the CMS to store uploaded files.

.htaccess rewrites

Humblee utilizes two different .htaccess files.

  1. The first is in the Humblee application root, ~/.htaccess. This file's primary purpose is to redirect all traffic to the ~/public folder as if it were the root of the application. In doing so, this effectively makes the "~/application," "~/humblee" and "~/storage" folders inaccessible from the web. When navigating to your-site.tld/application/js/myfile.js the file being loaded actually lives at public/application/js/myfile.js.
  2. The second rewrite happens in ~/public/.htaccess. This file allows any real files in the "~/public" directory to be read, such as the javascript and CSS assets stored in its subdirectories. However, if a given file does not exist in the public folder, the ~/public/index.php is called and the rest of the URL is passed as a variable to that script.

URI routing

Once the ~/public/index.php page is called, it, in turn, includes the file ~/humblee/init.php which initiates the rest of the Humblee framework and then loads the appropriate controller and calls the necessary method to load the given page specified by the URL.

A PHP switch() construct checks the passed URI and, if warranted, loads some predefined special controllers, such as the Humblee "admin" controller used by the CMS, the "users" controller for loading the sign in, authentication, and self-service user profile pages, and a "request" controller included in your ~/application/controllers folder that can be used for custom XHR (AJAX) calls you may wish to write.

By and large though, all traffic is routed to the default controller. This controller checks user authorization, finds data about the given page, retrieves all the content associated with the page and then loads the appropriate site and page templates. It also returns the ~/application/views/404.php view and a 404 header if the URI is not associated with a page created through the CMS.

Routing to a custom controller

If you are creating a custom controller that does not rely on pages or content created through the CMS, you can route to the controller directly from the ~/humblee/init.php file.

However, if your custom controller will be used by page templates created through the CMS, you must register it through the "Templates Manager". See the "Register new page templates" section of the templates documentation for more information.