Dummy - The framework for Dummies - Framework Reference

While in your controller, you can access any function of variable from the framework simply using $this (though there is always an active alias to $Dummy). Outside (like in global functions or the code inside your DefaultDummyController), you can still access there variables using the $Dummy alias (in functions, you will need to make it global or pass as parameter).

Before we get into the $Dummy object, here is a list of constants set at startup (in sys/Startup.php):

  • CONS_STARTTIME - Unix time when the script started
  • MEMORY_LIMIT - Numerical value of php's memory_limit
  • CONS_ONSERVER - boolean - if running on server or local (IP's considered locals are 10.0.*, 192.168.*, 127.0.* and ::1) - this is processed in Startup.php if you need to change.
  • CONS_IP - client IP
  • CONS_ISMOBILE - boolean if the client is accessing from a mobile device
  • CONS_GZIP_OK - boolean if the client browser accepts gzipped pages

The Dummy Class

Here is a full list of constants and variables for the $Dummy object defined in DummySettings class. Some are configuration related (first batch) and others function related.

Constants (only the useful ones, internal constants ommited)

  • CONS_LAYOUT_NORMAL ... CONS_LAYOUT_MOBILE - used by $Dummy->layout to define which type of page is being served;
  • CONS_UNIQUE_DAY ... CONS_UNIQUE_MINUTE - used by $Dummy->uniqueScript to define the current instance is running on a new day, hour or minute, useful to simulate Cron-like actions;
  • CONS_DEFAULT_EXT - which URL extension your pages are served. Usually, "html";
  • CONS_COOKIE_TIME - how long, in minutes, cookies last (used by statistic systems);
  • CONS_VAULT_FOLDER - which folder have files that should not be accessible directly to prevent hotlink (you will need to bar access to them manually on your .htaccess)
  • CONS_VAULT_CONFIG - settings on how to enable access to the above files using /download.php access.
  • PATH_ADM - which root path leads to the built-in administrative pane (leave blank if you don't want it to be used)

Variables

  • $Dummy->debugMode - boolean
    Either if running on debug mode, if true, will display the debug bar and allow ELI5, as well ignoring minor errors. 
     
  • $Dummy->debugbarPlace - string: top, right, bottom, left
    Where to place the debugbar on debug mode
     
  • $Dummy->autoTags - boolean
    Either to automatically apply default tags on the View(), this will remove context-sensitive tags like {_ajaxonly} or {_mobonly} depending on layout, as well fill constants like {PATH_FILES} (see source code for all tags)
     
  • $Dummy->dbConnector - string or boolean
    Either to use one database (string with a valid class inside /sys/dbo or true for mysqli) or not (false)
     
  • $Dummy->cms - boolean
    Either to run the CMS check or not. If true, the table for the CMS must be created in the database (see cms.xml)
     
  • $Dummy->jsminify - boolean
    Either if the View::compactjs will run or not. You can enclose javascript with tags (like {_javascript}) and call this function on that tag to minify it, but if jsminify is false that won't happen (good for debugging javascript)
     
  • $Dummy->validExtesions - array of strings
    Which file extensions are considered valid pages. If a call does not use one of these, the layout will be set to ajax mode. Default extensions are: 'html','htm','jsp','php','asp' and 'php3'
     
  • $Dummy->keepStatistics - boolean
    Either to run or not statistics keeping. If true, the statistics database must be set (see stats.xml) IMPORTANT: Set this in DummySettings, not in your master.php, as the administrative pane must have access to this variable prior to loading your controller.
     
  • $Dummy->keepLog - boolean
    If true, will keep a dummy.log file on root registering all $Dummy->errorLog entries
     
  • $Dummy->site_path - string
    The path to your site, as set on the $Dummy->start
     
  • $Dummy->config_path - string
    The path to your dynamic configuration files (dinConfig.dat)
     
  • $Dummy->installedDomains - array
    A list of valid domains the site is installed (include all variations, such as with and without www., don't forget to add localhost or 127.0.0.1 for local access) for the VAULT check system
     
  • $Dummy->vaultRedirect - string
    A file (located in the default view) that will be displayed if trying to access a file in the VAULT and the protection fails (like a no hot-link warning)
     
  • $Dummy->cacheEnabled - boolean
    Defines if the cache system is enabled
     
  • $Dummy->cacheRaw - boolean
    If raw files (set as layout raw, usually ajax files) are cached or not (default false)
     
  • $Dummy->cacheDuration - integer
    Time in minutes for cache duration, set 0 for forever (the administrative pane will reset all caches if you perform any action)
     
  • $Dummy->cacheConditions - array
    A list of $_SESSION variables that are used as flair for the cache system. You can also define specific conditions in those:
    ⋄ only variable name (example: "flair") - will just use as a flair for the cache seed
    ⋄ variable name = value (example: "flair=3") - cache will only be available if the variable is set accordingly
    ⋄ !variable (example: "!logged") - cache will only be available if the defined variable does not exist (is not set)
  • $Dummy->fullStatistics - boolean
    If the statistics system should also record referer, resolution and bots. These are a little more CPU/file intensive and not always necessary, so the default is off. The administrative pane won't show these if you disable it here.
     
  • $Dummy->peakAlertMail - string (a valid mail)
    If statistics is enabled, the system calculates the average daily access and if you have a peak access above 3x normal, it will trigger an E-mail warning to this mail, as well setting the dynamic variable "visitpeak" to 1. This is checked one every hour.

These are function/activity related, so change across the instance running:

  • $Dummy->original_path - string
    The raw original URI path for the page. Unaltered by routes and alias.
     
  • $Dummy->boottime - float
    Time (microseconds) it took to reach your controller code
     
  • $Dummy->db - cdbo object
    The database connector, an instance from /sys/dbo/
     
  • $Dummy->dc - DefaultDummyController object
    Your controller, which is set in /site/master.php
     
  • $Dummy->returnCode - string or int
    The HTTP return code for this call, defaults to 200 or 404 depending if page found. This regards only the HTTP code, but will force a 403, 404 or 500 default page to be displayed if $Dummy->viewServed is false (see below)
     
  • $Dummy->viewServed - boolean
    If a valid view (from a file or CMS) was served. This is about the page that will be show, not the HTTP return code. For instance, to have a custom 403 error depending on the situation, you can serve different views (which will trigger this flag to be true) but all with the returnCode set to 403
     
  • $Dummy->layout - int
    Which layout to be served, can be a number from 0 to 3 or one of the layout constants (in order): CONS_LAYOUT_NORMAL, CONS_LAYOUT_SIMPLE, CONS_LAYOUT_RAW, CONS_LAYOUT_MOBILE
     
  • $Dummy->workKey - string
    Your script key, set at $Dummy->start
     
  • $Dummy->warningLog - array
    Array or warning messages (always shown to the user)
     
  • $Dummy->errorLog - array
    Array of error messages (non fatal PHP errors will be redirected here). This is the array stored in /dummy.log if $Dummy->keepLog is true. These messages are only shown on debug mode.
     
  • $Dummy->uri - URI object
    Data about a URI path, including ->path (array of folders), ->action (filename) and ->ext . You can see the whole patch as a string invoking ->toString()
     
  • $Dummy->domain - string
    Which domain is being served
     
  • $Dummy->routes - array
    Array of your registered routes using $Dummy->route or $Dummy->domainRoute. You don't need to handle this directly;
     
  • $Dummy->view - View object
    Template object where your HTML is loaded into
     
  • $Dummy->cmscache - array or false
    A cache of data for the current CMS served page. Created when the script checks if there is a CMS data to be served, and used later after the template is ready to receive it. You don't need to handle this directly;
     
  • $Dummy->dinConfig - array or false
    Array from your dynamic configs. The default one, always loaded, is "dinConfig", from /site/dinConfig.dat. You can create and handle others using ->loadConfig and ->saveConfig
     
  • $Dummy->templateParams - array
    Array of parameters sent to View functions when required (mostly used by the admin module)
     
  • $Dummy->modules - array
    Array of meta data about your tables, used by the admin
     
  • $Dummy->cacheSeed - string
    Auto-generated seed for the cache system, contains at least the domain and layout, plus $Dummy->cacheConditions
     
  • $Dummy->cacheServed - boolean
    Set if the cache has already been served (the framework does not stop because it might need to record statistics and other php commands, so this is used to chech that)
     
  • $Dummy->uniqueScript - integer (see constants)
    Detects if this instance is the first to run at the current day, hour or minute. Useful to perform actions based on that;
     
  • $Dummy->lang - string with ISO 639-1 / ISO 3166-1 Alpha 2
    Language code for the page language being served (will be put in {PAGE_LANG} on your template;
     
  • $Dummy->hreflangs - array
    If you serve multiple languages, fill here the sets of language code => URL alternates. Language code must be ISO 639-1 / ISO 3166-1a2 and you MUST add the current language as well (Internet standard);
     
  • $Dummy->canonical - string
    The Canonical for the current page, which you can set or leave blank for automatic;

 

The Dummy instance


All the functions in $Dummy (not including constructor). Functions with a × are automatic and you don't need to worry (some are private):

  • $Dummy->start($site,$key,$externalConfig="")
    Handles all the workflow of the framework, this is the function you call at the index.php, explained in the Framework page
     
  • $Dummy->terminate($reason="")
    Ends the script. You can call this at any time if you want to end the script with any HTTP error like 403 or 404.
    This function will:
    1. Disconnect the database
    2. Load error page into the framework (if $viewServed is false or $reason is a numeric HTTP code)
    3. Fill canonical information into {canonical} and add the meta for canonical in the <head>, only if return code 200
    4. Manage hreflang tags based on yout $Dummy->hreflang arrays;
    5. Add a link rel tag in the <head> for your favicon (any file named favicon in your /files/ folder)
    6. Add debug or dummybar (ELI5) in the template
    7. Store $Dummy->errorLog messages if $Dummy->keepLog 
    8. Store the cache for the page, if it is not an error page and cache is selected.
    9. Output the template
    10. Stop the script (die) if $reason was not empty
       
  • × $Dummy->redirect($page,$folder=false)
    Performs an internal redirect to a new $page (optional new folder)
    For instance, if your current controller decides to serve another page, like a success or error page, you can use this function and the new page will be served as if the current. Runs automatically based on routes, moveout and domain routes.
     
  • × $Dummy->headerRedirect($location,$redirmode="200")
    Basically the same as the above but will halt the script by requesting an outside redirection using header(Location)
    $Dummy->redirect will not change the page url being served, if you need the url to change on the browser, this is better.
    Note you can store warning and queries from the current page to be loaded in the next using the $_SESSION[CONS_SESSION_LOG] (array of messages) and $_SESSION[CONS_SESSION_LOG_REQ] (array in the format $name=>$value that will be filled in $_REQUEST on the next page). Runs automatically on domain routes or redirect routes.
     
  • $Dummy->moveOut($localDomain,$localPagePattern,$destinationDomain,$destinationPage)
    Works like an immediate hard-coded routing to a new domain. If $localDomain is the current domain, and the page requested PREG_MATCH with $localPagePattern, will redirect (using $Dummy->headerRedirect) to $destinationDomain/$destinaionPage. A good place to use this is on your onStart() function
     
  • $Dummy->loadConfig($force=false, $file = "dinConfig")
    Loads the data of /site/dinConfig.dat in $Dummy->dinConfig. If already loaded or from cache (session), the $force parameter forces a reload. The cached data is stored only for 1 minute. Note it also uses a backup file (that is attempted if the main file fails) and a daily-backup file on worst case scenario (at which point, generates an error 500 if unable to load any). The main dinConfig is automatically loaded, but if you want to use another file, you will need to load it manually.
     
  • $Dummy->saveConfig($file = "dinConfig")
    Saves the data of $Dummy->dinConfig into /site/dinConfig.dat
    This function is never called automatically. Call it if you change data in $Dummy->dinConfig and wants it saved.
     
  • $Dummy->route($routeReg,$destinationRoute,$variablesArray=array(),$useHeader=false)
    Sets a route in the framework to be processed after everything is loaded. If the route matches ($routeReg = $Dummy->uri->toString()) will re-route to $destinationRoute and can set new variables in $_REQUEST if sent in $vadiablesArray. A good place to use this is on your onStart() function.
  • $Dummy->domainRoute($source,$new,$variablesArray=array(),$path='',$newTitle='')
    Same as above, but with domain names
     
  • × $Dummy->runRoutes()
    Called by the framework when it is time to check all routes
     
  • × $Dummy->getViewContent($file='',$asString=false)
    Loads data from a template file (or the current $Dummy->uri->toString()) and returns as a View object or string
     
  • × $Dummy->loadView($file='',$replaceCurrent=false)
    Simplified interface for $getViewContent used by the framework
     
  • × $Dummy->echoView($data,$replaceCurrent=false)
    Echos (or rather add to the template) a string (or View), depending if working on output buffered mode or not.
    If $replaceCurrent is set, will totally replace whatever is on the template, otherwise will append
     
  • × $Dummy->serveFixedFiles()
    Checks if the requested file is a fixed file and immediately serves it. The complete list of what are considered a fixed files are in /sys/fixedfiles.php (example of these files: robots.txt, favicon, apple-touch files)
     
  • $Dummy->prepareMail($ignoreVariables=array()
    Returns a View() object pre-constructed with the current $_REQUEST, useful to fill out automated mails.
     
  • × $Dummy->getCMS($fill=false)
    Checks if the current page have CMS data to be shown. If $fill is set, will assign {CONTENTMAN} with the page contents and set all meta data from the CMS file. This is all automatic by the framework so you don't need to use this. 
     
  • × $Dummy->showHeaders()
    Send headers with proper text translation (like 200 OK or 404 NOT FOUND)
     
  • × $Dummy->showDebugBar()
    Builds the debug bar for the terminate() function
     
  • × $Dummy->routeCompare($routeType,$route,$uri=false)
    Compares the given route with the optional $uri or current $Dummy->uri
     
  • × $Dummy->autoTags()
    Performs the autoTags pass, setting context-sensitive tags and adding constants.
     
  • × $Dummy->resetCMS()
    Recreates the CMS cache that handles pages from the content manager (stores in dinConfig which pages are CMS so it can detect them without consulting the database). This is called every time the CMS is changed on the administrative pane, or if you run debugmode.
     
  • $Dummy->currentPageIsCMS()
    Cheks if the page being called ($uri) is a page served by the CMS system.
     
  • × $Dummy->getCMS($fill = false)
    Fetches all the data for the current CMS page and will either load directly into the current view (if $fill is true) or will store in $Dummy->cmscache. Note all the CMS data is always stored in $Dummy->cmscache so you can also check this data in your code.
     
  • × $Dummy->checkCache($terminate = true)
    Cheks for a cached version of the current page ($uri), taking into consideration $_SESSION and $_REQUEST (will also respect $Dummy->cacheConditions). If found, will output the cached page and terminate. If $terminate is not set, will return true or false if a cache was served.
     
  • × $Dummy->purgeCache()
    Deletes all cached pages. Automatically called every time something is changed on the administrative pane or noCache is set in the $_REQUEST.
     
  • × $Dummy->saveCache(&$data)
    Stores the view ($data) as a cached version (serialized the object). Automatically called if a page is served and can be cached.

 

◀ Back

Check other of my articles, like: What changed in the world since you were born?