This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

The concrete5 Loader library provides access to all commonly used concrete5 objects. Generally, no direct require() or include() calls should be made.

NOTE: All references to filenames should NOT include .php in their arguments.

Order of Precedence

Generally, whenever an item is loaded, it will be looked for in the following places, in the following order:

  1. Local directories (in the web root)
  2. If a package is specified, it will be looked for in the local packages directory.
  3. If a package is specified, it will now be looked for in the concrete/packages directory
  4. If a package is NOT specified, it will now be looked for in the concrete/ directory

Methods

Loader::library($library, $pkgHandle = null)

Loads a file in the libraries/ and concrete/libraries/ folder. If $pkgHandle is passed, it will be looked for in the local libraries directory, and the local packages/$pkgHandle/libraries directory.

	Loader::library('my_date_library');

Looks for libraries/my_date_library.php and concrete/libraries/my_date_library.php.

Loader::library('my_date_library', 'calendar')

Looks for packages/calendar/libraries/my_date_library.php.

Loader::model($model, $pkgHandle = null)

Loads a file in the models/ and concrete/models/ folder. If $pkgHandle is passed, it will be looked for in the local models directory, and the local packages/$pkgHandle/models directory.

Loader::element($file, $args = null)

Loads a file in the elements/ directory and concrete/elements/ directory. Uses the include() function to include this file. $args is an optional PHP associative array that, if passed, will be run through PHP's extract() function, so that the keys of the array are available as variables in the local scope.

Loader::packageElement($file, $pkgHandle, $args = null)

Loads a file in the packages/$pkgHandle/elements/ directory or concrete/packages/$pkgHandle/elements/ directory. Uses the include() function to include this file. $args is an optional PHP associative array that, if passed, will be run through PHP's extract() function, so that the keys of the array are available as variables in the local scope.

Loader::block($blockTypeHandle)

Loads the controller for a block type, typically found at either blocks/$blockTypeHandle/controller.php or concrete/blocks/$blockTypeHandler/controller.php

Loader::db()

Grabs the currently active database object and makes it available in the current scope.

	function myFunction() { 		$db = Loader::db(); 		$db->Execute('select * from MyTable'); 		// ... etc ... 	}

$helper = Loader::helper($file, $pkgHandle = false)

Loads a helper class from the local helpers directory or concrete/helpers/ directory. If $pkgHandle is specified then packages/$pkgHandle/helpers/ will be looked at instead.

The instance of the class is then returned.

Note: if the helpers file exists in the local directory and in the core directory, and the class name in the local directory begins with Site, it is understood that this site helper actually extends the core helper, and the core helper will be loaded as well. 

$package = Loader::package($pkgHandle)

Loads and instantiates a package controller class. *Note*: This is not the same as the package object. This is simply an instance of packages/$pkgHandle/controller.php

Loader::controller($item)

Loads the controller for a particular path. *Note*: leave off the initial forward slash.

Loader::controller("dashboard/users/search"); 	$cnt = DashboardUsersSearch(); 	$cnt->doSomething();

If the $item is actually a page, the page's controller will be loaded.

$c = Page::getByPath('/members'); 	Loader::controller($c); 	$cnt = MembersController();
Loading Conversation