Site Class
This is the main class of the framework that needs to be implemented in order to use. Canteen is a backend which provides a JSON server, Database connect, template engine, User authentication and many other features for building very dynamic data-driven websites.
// Externally load the deployment settings from a PHP file (default)
$site = new Canteen\Site('config.php');
// Or set the single deployment settings directly
$site = new Canteen\Site([
'dbUsername' => 'user',
'dbPassword' => 'pass1234',
'dbName' => 'my_settingsbase',
]);
// Or create different deployments of the site
// for different domains where the site is hosted
$site = new Canteen\Site([
// our local site accessible from http://localhost
[
'level' => DeploymentStatus::LOCAL,
'domain' => 'localhost',
'dbUsername' => 'root',
'dbPassword' => '',
'dbName' => 'my_settingsbase',
'debug' => true
],
// Our dev site accessible from http://dev.example.com
[
'level' => DeploymentStatus::DEV,
'domain' => 'dev.example.com',
'dbUsername' => 'user',
'dbPassword' => 'pass1234',
'dbName' => 'my_dev_settingsbase',
'debug' => true
],
// Our live site accessible from http://example.com
[
'level' => DeploymentStatus::LIVE,
'domain' => 'example.com',
'dbUsername' => 'user',
'dbPassword' => 'pass1234',
'dbName' => 'my_settingsbase',
'minify' => true,
'compress' => true,
'cacheEnabled' => true
]
]);
// Echo out the page result
$site->render();
Constructor
Site
-
[settings='config.php']
-
[callerPath=null]
Parameters:
-
[settings='config.php']
String | Array | Dictionary optionalThe path to the settings PHP, the collection of deployment settings, or the single deployment dictionary.
-
dbUsername
StringThe username for the database
-
dbPassword
StringThe password for the database
-
dbName
String | DictionaryThe name of the database or collection of aliases and databases ('default' is required)
-
[dbHost='localhost']
String optionalThe name of the database host
-
[level=DeploymentStatus::LIVE]
Int optionalThe deployment level of the site, see DeploymentStatus class for more info
-
[domain='*']
Array | String optionalSingle domain or collection of domains acceptable for this deployment to run
-
[debug=false]
Boolean optionalThe debug mode
-
[cacheEnabled=false]
Boolean optionalIf the cache is enabled
-
[compress=false]
Boolean optionalIf the site should be compressed with gzip
-
[minify=false]
Boolean optionalIf the output page should be minified
-
[cacheDirectory=null]
String optionalThe directory for storing file cache if Memcache isn't available
-
-
[callerPath=null]
String optionalThe path to the root script of the site, useful if we are inheriting this class.
Item Index
Methods
Properties
- _controllers
- _instance static
- browserUri
- cache
- db
- DB_VERSION static
- formFactory
- gateway
- logoutUri
- MAIN_TEMPLATE static
- MIN_PHP_VERSION static
- parser
- profiler
- settings
- startTime
- user
- VERSION static
Methods
addController
-
pageUri
-
controllerClassName
Store a page user function call for dynamic pages
addSetting
-
name
-
value
-
[client=true]
-
[renderable=true]
Set the configuration setting
errorHandler
-
e
Handle PHP errors, like wrong argument counts
Parameters:
-
e
ExceptionThe caught exception
fatalError
-
e
Create a fatalError
Parameters:
-
e
ExceptionThe caught exception
getController
-
pageUri
Get a page controller by uri
Parameters:
-
pageUri
StringThe uri of the page
Returns:
The controller matching the URI
instance
()
Canteen
static
Get the singleton instance
Returns:
The singleton instance of ServerCache
isDatabaseUpdated
-
variableName
-
targetVersion
-
updatesFolder
Check to make sure the database is up-to-date
render
-
[capture=false]
Get the current page markup, echoes on the page
Parameters:
-
[capture=false]
Boolean optionalIf we should return the page render (false) or echo (true)
Returns:
If capture is true, return the page render as a string
requiresVersion
-
required
Check that a version of Canteen is required to run
Parameters:
-
required
StringThe least required version to run
Properties
_instance
Canteen
private
static
The singleton instance
db
Database
The instance of the database for fetching data using SQL
parser
Parser
The template parser
// Add a template to the site
$site->parser->addTemplate('Footer', 'Templates/Footer.html');
// Or add a JSON manifest with an array of template files
$site->parser->addManifest('templates.json');
profiler
Profiler
The Profiler is use for debugging performance issues, SQL speed
startTime
Int
The starting time to keep track of buildtime