A script to provide the bare minimum to start building a PHP/MooTools powered website. Used for small projects, where it's feasible to get cracking right away. Of course you could copy/paste files from one project to the other every time, but now you don't have to worry about leftover data polluting your files.
Requires PHP5.x and directory read/write permissions to use.
Please note: only tested on Windows. Not likely to work on Linux/Mac (as of now)
This installer is meant for small projects, where you want a basic setup with convenient functions. Launch the script, test if it works and start coding with a working environment in under a minute.
It features the following functionalities:
- A basic mysql connection with INSERT, UPDATE, DELETE and plain query functions.
- A primitive PHP templating system
- Ajax calls in Javascript and handling in PHP
- html5doctor.com's CSS reset stylesheet
- MooTools 1.4.5 (non-compressed)
- A clear and clean folder structure
The installer uses $_SERVER['DOCUMENT_ROOT']
as its base for installations.
- Run the installer from your browser.
- Enter the location where you want to install to. Note: if you choose an existing folder, it will overwrite conflicting files.
- Optional: enter your database details. This will only be saved for the current process.
- Overview page. Click 'Install' to start.
- Click 'Go!' to visit your newly created project.
- Test the Ajax call function
- Test the database connection, if you filled in the correct details at step 3
- 'Final preparations' removes all the test-data and presents you with a clean project
The following filetree is created:
- classes
- Ajax.class.php
- Db.class.php
- Site.class.php
- Template.class.php
- css
- reset.css
- styles.css
- inc
- definitions.inc.php
- js
- Site.js
- mootools-core-1.4.5-full-nocompat-yc.js
- templates
- content-default.php
- footer.php
- header.php
- index.php
Calls Site.class.php and initiates page
The heart of all interaction between JS and PHP, this file handles all Ajax requests.
function getRequest($request [, $data])
Returns called function
Looks for the request literally as a function, else use switch-statement
function getDefault([ $data ])
Returns content-default.php template
Database class
function query([ $query ])
Returns error or empty set or results
function insert($table, $data = array())
Returns error or true
$table
Table name
$data
Data to be inserted
Array(
'column_name1' => 'value1',
'column_name2' => 'value2'
);
function update($table, $id, $data = array())
Returns error or true
$table
Table name
$id
Row where 'id'
$data
Data to be inserted
Array(
'column_name1' => 'value1',
'column_name2' => 'value2'
);
function delete($table, $id)
Returns error or true
$table
Table name
$id
Row where 'id' to delete
Main class
Initiates $_SESSION, loads inc/definitions.inc.php, assigns autoloader, initiates classes, processes Ajax-requests
function getPage()
Returns default page
function error($errorMsg [, $line = 'undefined', $file = 'undefined'])
Basic errors
Returns error message
$errorMsg
Error message to return
$line
Line number
$file
File
Html5doctor.com reset stylesheet
Empty stylesheet file
Set Database constants. If provided in the installation, this should be filled in.
MooTools core version 1.4.5, non-compressed
Main MooTools javascript
ajaxRequest: function(request, data, success)
Returns function call return or console.log(error)
Processes Ajax-requests
request
Function to call
data
JSON object with data to transfer
success
Callback function on success
$('button').addEvent('click', function(event) {
this.ajaxRequest('getDefault', {
key1: 'value1',
key2: {
key2a: 'value2a',
key2b: 'value2b'
}
},
function(response) {
console.log(response);
})
});
Example empty template file, is called on initial loading of page
Closes HTML tags
Calls HTML header with HTML5 doctype, stylesheets and javascript files