$config->setLocation() method

Given a directory to a named location, updates $config->paths and $config->urls for it

  • Paths relative to PW installation root should omit the leading slash, i.e. use site/templates/ and NOT /site/templates/.

  • If specifying just the $dir argument, it updates both $config->paths and $config->urls for it.

  • If specifying both $dir and $url arguments, then $dir refers to $config->paths and $url refers to $config->urls.

  • The $for argument can be: cache, logs, files, tmp, templates, or one of your own. Other named locations may also work, but since they can potentially be used before PW’s “ready” state, they may not be reliable.

  • Warning: anything that changes a system URL may make the URL no longer have the protection of the root .htaccess file. As a result, if you modify system URLs for anything on a live server, you should also update your .htaccess file to reflect your changes (while leaving existing rules for original URL in place).

The following example would be in /site/init.php or /site/ready.php (or equivalent module method). In this example we are changing the location (path and URL) of our /site/templates/ to use a new version of the files in /site/dev-templates/ so that we can test them out with user 'karen', while all other users on the site get our regular templates.

Available since version 3.0.141.

Example

// change templates path and URL to /site/dev-templates/ when user name is 'karen'
if($user->name == 'karen') {
  $config->setLocation('templates', 'site/dev-templates/');
}

Usage

// basic usage
$self = $config->setLocation(string $for, string $dir);

// usage with all arguments
$self = $config->setLocation(string $for, string $dir, $url = '');

Arguments

NameType(s)Description
forstring

Named location from $config->paths or $config->urls, one of: cache, logs, files, tmp, templates, or your own.

dirstring

Directory or URL to the location. Should be either a path or URL relative to current installation root (recommended), or an absolute disk path that resolves somewhere in current installation root. If specifying an absolute path outside of the installation root, then you’ll also want to provide the $url argument since PW won’t know it. You may also specify a blank string for this argument if you only want to set the $url argument.

url (optional)string, bool

If the $dir argument represents both the path and URL relative to site root, you can omit this argument. If path and URL cannot be derived from one another, or you only want to modify the $url (leaving $dir blank), you can specify the URL in this argument. Specify boolean false if you only want to set the $dir (path) and not detect the $url from it.

Return value

self

Exceptions

Method can throw exceptions on error:

  • WireException - If request cannot be accommodated


$config methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #523
    In the 523rd issue of ProcessWire Weekly we'll check out what's new in the core this week, share some new module related news, and more. Read on!
    Weekly.pw / 18 May 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH