Trivial - the ultra-lightweight Web framework for PHP
Installation
Installation is done via RubyGems:
gem install trivial
A new binary is created, trivialize.
Creating a new site
cd to the directory where you want your new site and type:
trivialize my-new-site
A directory called my-new-site will be created with the site structure in place. An example content/index.html and views/application.inc will also be installed.
Upgrading an existing site
Backup your existing site folder, cd to the site folder and type:
trivialize --upgrade
The following files will be overwritten:
lib/trivial.phpstyles/blueprint
And if they don't exist, the following files will be created:
config/trivial.inc
The request process
When a request comes in to that directory for a file that doesn't exist, trivial
does the following (for the examples, the request was for about_us/contact.html and the default $layout value is "application"):
- The
contentfolder is checked for an.htmlor.incfile that matches the path (content/about_us/contact.html).- If a
.htmlfile exists, the contents of the file are pulled into the global$contentvariable. - If a
.incfile exists, the file is include()d and the output is placed into the global$contentvariable.
- If a
- The
actionsfolder is checked for two files:actions/application.inc-
actions/about_us/contact.incEach found file is included into the program in that order, potentially modifying$contentor$layout.
- The
viewsfolder is checked for two files:views/about_us/contact.inc-
views/application.incEach found file is included into the program, including$contentwhere specified and outputting back into$content. A layout must exist or an error will occur.
- The value of
$contentis output to the visitor.
Styles and scripts
By default, the provided views/application.inc file has three functions for including stylesheets and scripts:
<head>
<?php echo blueprint() ?>
<?php echo scripts() ?>
<?php echo styles() ?>
</head>
Blueprint
The latest Blueprint CSS Framework comes with Trivial. It's included into the defaut application.inc layout
with the blueprint() function. Blueprint's licence can be found in the styles/blueprint directory.
Other Styles and Scripts
The scripts() and styles() functions, by default, only search for files named application.ext and name/of/request.ext.
For the request contact/about_us.html, the following JavaScript and CSS files will be searched for, in this order:
scripts/application.jsscripts/contact/about_us.jsstyles/application.cssstyles/contact/about_us.css
You can incude other scripts and stylesheets in several ways:
Globally, before application- and page-specific includes
Inside of config/trivial.inc, add the following variable definition:
$global_head = array('scripts' => array(), 'styles' => array());
In the scripts and styles arrays, add the names of the other files to include, not including the extension:
$global_head = array('scripts' => array('jquery-1.4.2.min'), 'styles' => array('client'));
These scripts are loaded before the ones listed above, so the new search path becomes:
scripts/jquery-1.4.2.min.jsscripts/application.jsscripts/contact/about_us.jsstyles/client.cssstyles/application.cssstyles/contact/about_us.css
Locally, via a view, before application- and page-specific includes
In your view, modify $global_head as you would above.
Within the layout, without adding new script() or style() tags
Adding additional parameters to the scripts() or styles() tag works the same as adding items to the $global_head:
<?php echo scripts('jquery-1.4.2.min') ?>
<?php echo styles('client') ?>
Scripts/styles defined in the tag itself are loaded before $global_head.