Fabriq Framework Docs

This page displays the APIs for the Fabriq framework that are made available by the /core/Fabriq.class.php file's Fabriq class. Each function available for use is listed below with examples of how to use the function.

Fabriq::action($a = NULL)

Parameters

  • a (optional) – name of the action to set to be rendered (used only by core)

Description

This function is called by index.php to set the initial action to be rendered

NOTE: this function was moved to the /core/BaseMapping.class.php file. To use the action function, it can be called using PathMap::action(). Please update your code to use the new version. The /app/PathMap.class.php extends the /core/BaseMapping.class.php. Only the /app/PathMap.class.php file should be edited.

Example(s)

// deprecated example
echo "The action called was " . Fabriq::action();
// new version
echo "The action called was " . PathMap::action();

Deprecated in version: 0.8

Removed in version: 0.12

Return type: string

Fabriq::add_css($stylesheet, $media = 'screen', $path = 'public/stylesheets/', $ext = '.css')

Parameters

  • stylesheet – the name of the stylesheet (without the .css extension)
  • media (optional) default value: 'media' – the type of stylesheet being included
  • path (optional) default value: 'public/stylesheets/' – the path of the location of the stylesheet (often set whenever pulling a stylesheet from an external location)
  • ext (optional) default value: '.css' – the extension of the stylesheet file

Description

This function is called whenever the developer is adding a CSS file to the CSS queue to be included in the display of the page. The function is typically called in a controller file. NOTE: the files in the CSS queue are only included when in layout mode unless the developer has written code in the view to include the files in the CSS queue. The file extension can be set if the CSS is generated by a PHP or other script.

Example(s)

// example 1 - basic use
Fabriq::add_css('users');
// example 2 - a print stylesheet
Fabriq::add_css('users', 'print');
// example 3 - an external stylesheet
Fabriq::add_css('users', 'screen', 'http://example.com/');
// example 4 - a generated css script
Fabriq::add_css('blogs', 'screen', 'public/stylesheets/', ".php?user={$user->id}");

Fabriq::add_js($javascript, $path = 'public/javascripts/', $ext = '.js')

Parameters

  • javascript – the name of the stylesheet (without the .js extension)
  • path (optional) default value: 'public/javascripts/' – the path of the location of the JavaScript file (often set whenever pulling a JavaScript file from an external location)
  • ext (optional) default value: '.js' – the file extension of the JavaScript file being included. The extension can be changed in cases where the script is dynamically generated.

Description

This function is called whenever the developer is adding a JavaScript file to the JavaScript queue to be included in the rendering of the page. The function is typically called in a controller file. NOTE: the files in the JavaScript queue are only included when in layout mode unless the developer has written code in the view to include the files in the JavaScript queue.

Example(s)

// example 1 - basic use
Fabriq::add_js('query.min');
// example 2 - include a JavaScript file at the given path
Fabriq::add_js('jquery.min', 'http://code.jquery.com/');
// example 3 - use a JavaScript file with a file extension other than .js
Fabriq::add_js('users', 'http://example.com/', '.php');

Fabriq::arg($index, $val = NULL)

Parameters

  • index – the index of the argument in the query arguments variable
  • val (optional) default value: NULL – if a value is given, the argument at that index is set to val

Description

The Fabriq::arg() function is the getter/setter for arguments in the query arguments variable. If a second parameter is passed in, the argument at the given index is set to the given value of the second parameter.

NOTE: this function was moved to the /core/BaseMapping.class.php file. To use the action function, it can be called using PathMap::arg(). Please update your code to use the new version. The /app/PathMap.class.php extends the /core/BaseMapping.class.php. Only the /app/PathMap.class.php file should be edited.

Example(s)

//// deprecated examples
// example 1a - get an argument
echo Fabriq::arg(2);
// example 2a - set an argument
Fabriq::arg(2, $id);
//// examples that should be used
// example 1b - get an argument
echo PathMap::arg(2);
// example 2b - set an argument
PathMap::arg(2, $id);

Deprecated in version: 0.8

Removed in version: 0.12

Return type: object

Fabriq::base_path()

Description

This function returns the base path of the application that is stored in the config file. The results of the function can be used for building paths when not using Fabriq::link_to().

NOTE: this function was moved to the /core/BaseMapping.class.php file. To use the action function, it can be called using PathMap::base_path(). Please update your code to use the new version. The /app/PathMap.class.php extends the /core/BaseMapping.class.php. Only the /app/PathMap.class.php file should be edited.

Example(s)

//// deprecated
// example displaying the base path to the output
echo Fabriq::base_path();
//// example that should be used
// example displaying the base path to the output
echo PathMap::base_path();

Deprecated in version: 0.8

Removed in version: 0.12

Return type: string

Fabriq::build_path()

Description

The Fabriq::build_path() function is used to build a path to be used in Fabriq applications. The function can be used when building a path for the action attribute of a form element in a view.

NOTE: this function was moved to the /core/BaseMapping.class.php file. To use the action function, it can be called using PathMap::build_path(). Please update your code to use the new version. The /app/PathMap.class.php extends the /core/BaseMapping.class.php. Only the /app/PathMap.class.php file should be edited.

Example(s)

// deprecated example
<form method="post" action="<?php echo Fabriq::build_path('blog', 'create'); ?>">
<!-- form code -->
</form>

// example that should be used
<form method="post" action="<?php echo PathMap::build_path('blog', 'create'); ?>">
<!-- form code -->
</form>

Deprecated in version: 0.8

Removed in version: 0.12

Return type: string

Fabriq::clean_urls()

Description

Returns whether or not the Fabriq application is using clean URLs based on the setting in the configuration file.

NOTE: this function was moved to the /core/BaseMapping.class.php file. To use the action function, it can be called using PathMap::clean_urls(). Please update your code to use the new version. The /app/PathMap.class.php extends the /core/BaseMapping.class.php. Only the /app/PathMap.class.php file should be edited.

Example(s)

// deprecated example
if (Fabriq::clean_urls()) {
  // tasks to perform if using clean URLs
}
// example that should be used
if (PathMap::clean_urls()) {
  // tasks to perform if using clean URLs
}

Deprecated in version: 0.8

Removed in version: 0.12

Return type: boolean

Fabriq::clean_urls_str()

Description

Returns a string version of the boolean for whether or not the Fabriq application is using clean URLs based on the setting in the configuration file.

NOTE: this function was moved to the /core/BaseMapping.class.php file. To use the action function, it can be called using PathMap::clean_urls_str(). Please update your code to use the new version. The /app/PathMap.class.php extends the /core/BaseMapping.class.php. Only the /app/PathMap.class.php file should be edited.

Example(s)

// deprecated example
echo "This site uses clean URLs: " . Fabriq::clean_urls_str();
// example that should be used
echo "This site uses clean URLs: " . PathMap::clean_urls_str();

Deprecated in version: 0.8

Removed in version: 0.12

Return type: string

Fabriq::controller($c = NULL)

Parameters

  • c (optional) – name of the controller to set to be rendered (used only by core)

Description

This function is called by index.php to set the initial controller to be rendered

NOTE: this function was moved to the /core/BaseMapping.class.php file. To use the action function, it can be called using PathMap::controller(). Please update your code to use the new version. The /app/PathMap.class.php extends the /core/BaseMapping.class.php. Only the /app/PathMap.class.php file should be edited.

Example(s)

// deprecated example
echo "The controller called was " . Fabriq::controller();
// example that should be followed
echo "The controller called was " . PathMap::controller();

Deprecated in version: 0.8

Removed in version: 0.12

Return type: string

Fabriq::cssqueue()

Description

Returns the list of CSS files that are in the CSS queue. This function is used in the default layout file located in /app/views/layouts/application.view.php to include the stylesheets in the queue.

Example

// code used in the /app/views/layouts/application.view.php
foreach (Fabriq::cssqueue() as $css) {
  echo "<link href=\"{$css['path']}{$css['css']}.css\" media=\"{$css['media']}\" rel=\"stylesheet\" type=\"text/css\" />\n";
}

Return type: array

Fabriq::fabriq_error()

Description

Stops execution of code and displays the server error page stored in the /public directory.

Example(s)

if (!$something) {
  Fabriq::fabriq_error();
}

Fabriq::installed()

Description

Used by the index.php file to determine whether or not the configuration file exists. If the configuration file does not exist, the index.php file attempts to call the install.php file to walk the developer through the steps of creating the configuration file.

Fabriq::jsqueue()

Description

Returns the list of JavaScript files that are in the JavaScript queue. This function is used in the default layout file located in /app/views/layouts/application.view.php to include the JavaScript files in the queue.

Example

// code used in the /app/views/layouts/application.view.php
foreach (Fabriq::jsqueue() as $js) {
  echo "<script language=\"JavaScript\" type=\"text/javascript\" src=\"{$js['path']}{$js['js']}{$js['ext']}\"></script>\n";
}

Return type: array

layout($l = NULL)

Parameters

  • l (optional) default: NULL – the layout to use

Description

Get or set the layout to be used. Called in controller actions.

Example(s)

// get the layout
echo Fabriq::layout();
// set the layout
Fabriq::layout('account');

Return type: string

Fabriq::link_to($linktext, $controller, $action = NULL, $queries = false, $blank = false, $title = NULL)

Parameters

  • linktext – text/content to be linked
  • controller – controller to be linked to
  • action (optional) default value: NULL – action to be linked to
  • queries (optional) default value: false – an array of items to append to the query argument
  • blank (optional) default value: false – whether or not to open the link in a new browser window/tab
  • title (optional) default value: NULL – title to display when a viewer hovers over a link

Description

Builds a link to another part of the Fabriq website or application. Using this function is preferable to using the HTML <a> tag because it generates the proper link whether clean URLs are enabled. Using this functionality is better if creating a website or application that will be deployed on different servers.

Example(s)

// basic usage
Fabriq::link_to('Click here', 'ctrl');
// linking to a specific action
Fabriq::link_to('Click here', 'ctrl', 'alt');
// creating a link with additional arguments
Fabriq::link_to('Click here', 'blog', 'view', array(15349));
// opening a link in a new window
Fabriq::link_to('Click here', 'blog', 'create', false, true);
// adding a title to the link
Fabriq::link_to('Click here', 'blog', 'index', false, false, 'View a list of the most recent blog entries');

Fabriq::model($model)

Parameters

  • model - the name of the model to include

Description

Includes the given model. NOTE: when naming model files, the name of the file should match the model (ex: a model named Users should be in the file Users.model.php)

Example(s)

Fabriq::model('Users');

Deprecated in version: 0.11

Removed in version: 0.12

Fabriq::page_js_on()

Description

This function is called in a controller's action method to add a controller's JavaScript file located in the /app/scripts/ directory to the JavaScript queue.

Example(s)

// users controller class located in /app/controllers/users.controller.php
class users_controller extends Controller {
  function login() {
    Fabriq::page_js_on();
    // login action code...
  }
}

Fabriq::render($r = NULL)

Parameters

  • r default value: NULL – the type of render to process

Description

This function tells Fabriq what type of render to process. The function works as a getter and setter for the render option. Recognized values are layout, view, none, and NULL. The default render set by Fabriq is layout. If NULL is passed in or the function is called with no parameters, the function returns the current render option.

Example(s)

// example blog controller class
class blog_controller extends Controller {
  public function create() {
    Fabriq::render('layout');
    // create action code...
  }
 
  public function read() {
    Fabriq::render('view');
    // read action code...
  }
 
  public function destroy() {
    Fabriq::render('none');
    // destroy action code...
  }
}

Return type: string

Fabriq::render_action($a = NULL)

Parameters

  • a default value: NULL – the action to render

Description

This function acts as a getter and setter for the render action to be executed. If the value is different from action, then the render action is executed after the action. If NULL is passed in, the render action name is returned.

NOTE: this function was moved to the /core/BaseMapping.class.php file. To use the action function, it can be called using PathMap::render_action(). Please update your code to use the new version. The /app/PathMap.class.php extends the /core/BaseMapping.class.php. Only the /app/PathMap.class.php file should be edited.

Example(s)

// deprecated example
echo "The render action being executed is: " . Fabriq::render_action();
// example that should be followed
echo "The render action being executed is: " . PathMap::render_action();

Deprecated in version: 0.8

Removed in version: 0.12

Return type: string

Fabriq::render_controller($c = NULL)

Parameters

  • c default value: NULL –

Description

This function acts as a getter and setter for the render controller to be executed. If the value is different from controller, then the render action in the render controller is executed after the action in the controller. If NULL is passed in, the render controller name is returned.

NOTE: this function was moved to the /core/BaseMapping.class.php file. To use the action function, it can be called using PathMap::render_controller(). Please update your code to use the new version. The /app/PathMap.class.php extends the /core/BaseMapping.class.php. Only the /app/PathMap.class.php file should be edited.

Example(s)

// deprecated example
echo "The render controller that may execute the render action is: " . Fabriq::render_controller();
// example that should be followed
echo "The render controller that may execute the render action is: " . PathMap::render_controller();

Deprecated in version: 0.8

Removed in version: 0.12

Return type: string

Fabriq::title($title = NULL)

Parameters

  • title

Description

This function acts as the getter and setter for the page title. The function is usually called in controller actions and passed in a page title. It is automatically called in the /app/views/layouts/application.view.php file to set the page title in the <title> tag of the page.

Example(s)

// example photo controller class
class photos_controller extends Controller {
  public function read() {
    // get the photo information
    Fabriq::title('Photo: ' . $photo->name);
    // more code for the read action
  }
}

Return type: string