public static
|
#
addRules( mixed $priority, mixed $rules )
Add URL matching rules to the Director.
Add URL matching rules to the Director.
The director is responsible for turning URLs into Controller objects.
Parameters
- $priority
mixed $priority The priority of the rules; higher values will get your rule checked
first. We recommend priority 100 for your site's rules. The built-in rules are
priority 10, standard modules are priority 50.
- $rules
|
public static
|
#
direct( mixed $url, DataModel $model )
Process the given URL, creating the appropriate controller and executing
it.
Process the given URL, creating the appropriate controller and executing
it.
Request processing is handled as follows: - Director::direct() creates a new
SS_HTTPResponse object and passes this to Director::handleRequest(). -
Director::handleRequest($request) checks each of the Director rules and
identifies a controller to handle this request. -
Controller::handleRequest($request) is then called. This will find a rule to
handle the URL, and call the rule handling method. -
RequestHandler::handleRequest($request) is recursively called whenever a rule
handling method returns a RequestHandler object.
In addition to request processing, Director will manage the session, and
perform the output of the actual response to the browser.
Parameters
- $url
mixed $url String, the URL the user is visiting, without the querystring.
- $model
Uses
Director::handleRequest()rule-lookup logic is handled by this.
Controller::run() Controller::run() handles the page logic for a
Director::direct() call.
|
public static
SS_HTTPResponse
|
#
test( string $url, array $postVars = null, Session $session = null, string $httpMethod = null, string $body = null, array $headers = null, array $cookies = null, HTTP_Request & $request = null )
Test a URL request, returning a response object.
Test a URL request, returning a response object.
This method is the counterpart of Director::direct() that is used in
functional testing. It will execute the URL given, and return the result as an
SS_HTTPResponse object.
Parameters
- $url
string $url The URL to visit
- $postVars
array $postVars The $_POST & $_FILES variables
- $session
Session $session The Session object representing the current session. By passing
the same object to multiple calls of Director::test(), you can simulate a
persisted session.
- $httpMethod
string $httpMethod The HTTP method, such as GET or POST. It will default to POST if
postVars is set, GET otherwise. Overwritten by $postVars['_method'] if present.
- $body
string $body The HTTP body
- $headers
array $headers HTTP headers with key-value pairs
- $cookies
array $cookies to populate $_COOKIE
- $request
HTTP_Request $request The HTTP_Request object generated as a part of this request
Returns
Uses
getControllerForURL() The rule-lookup logic is handled by this.
Controller::run() Controller::run() handles the page logic for a
Director::direct() call.
Used by
|
protected static
SS_HTTPResponse|string
|
|
public static
|
#
urlParam( mixed $name )
Returns the urlParam with the given name
Returns the urlParam with the given name
Deprecated
3.0 Use SS_HTTPRequest->param()
|
public static
|
#
urlParams( )
Returns an array of urlParams.
Returns an array of urlParams.
Deprecated
3.0 Use SS_HTTPRequest->params()
|
public static
|
#
setUrlParams( mixed $params )
Set url parameters (should only be called internally by
RequestHandler->handleRequest()).
Set url parameters (should only be called internally by
RequestHandler->handleRequest()).
Parameters
- $params
mixed $params array
|
public static
SiteTree
|
#
get_current_page( )
Return the SiteTree object that is currently being viewed. If there
is no SiteTree object to return, then this will return the current
controller.
Return the SiteTree object that is currently being viewed. If there
is no SiteTree object to return, then this will return the current
controller.
Returns
|
public static
|
#
set_current_page( SiteTree $page )
Set the currently active SiteTree object that is being used to
respond to the request.
Set the currently active SiteTree object that is being used to
respond to the request.
Parameters
|
public static
|
#
absoluteURL( mixed $url, mixed $relativeToSiteBase = false )
Turns the given URL into an absolute URL.
Turns the given URL into an absolute URL.
|
public static
boolean|string
|
#
protocolAndHost( )
Returns the part of the URL, 'http://www.mysite.com'.
Returns the part of the URL, 'http://www.mysite.com'.
Returns
boolean|string The domain from the PHP environment. Returns FALSE is this environment variable
isn't set.
|
public static
String
|
#
protocol( )
Return the current protocol that the site is running under
Return the current protocol that the site is running under
Returns
String
|
public static
|
#
redirect( mixed $url, mixed $code = 302 )
Redirect to another page.
Redirect to another page.
Deprecated
2.5 Use Controller->redirect() - $url can be an absolute URL - or it can be a
URL relative to the "site base" - if it is just a word without an slashes, then
it redirects to another action on the current controller.
|
public static
string
|
#
redirected_to( )
Tests whether a redirection has been requested.
Tests whether a redirection has been requested.
Deprecated
2.5 Use Controller->redirectedTo() instead
Returns
string If redirect() has been called, it will return the URL redirected to. Otherwise,
it will return null;
|
public static
|
#
set_status_code( mixed $code )
Sets the HTTP status code
Sets the HTTP status code
Deprecated
2.5 Use Controller->getResponse()->setStatusCode() instead
|
public static
|
#
get_status_code( )
Returns the current HTTP status code
Returns the current HTTP status code
Deprecated
2.5 Use Controller->getResponse()->getStatusCode() instead
|
public static
|
|
public static
|
#
baseURL( )
Returns the root URL for the site. It will be automatically calculated unless
it is overridden with Director::setBaseURL().
Returns the root URL for the site. It will be automatically calculated unless
it is overridden with Director::setBaseURL().
Used by
|
public static
|
#
setBaseURL( mixed $baseURL )
Sets the root URL for the website. If the site isn't accessible from the URL
you provide, weird things will happen.
Sets the root URL for the website. If the site isn't accessible from the URL
you provide, weird things will happen.
|
public static
|
|
public static
|
#
setBaseFolder( mixed $baseFolder )
Sets the root folder for the website. If the site isn't accessible from the
folder you provide, weird things will happen.
Sets the root folder for the website. If the site isn't accessible from the
folder you provide, weird things will happen.
|
public static
string
|
#
makeRelative( string $url )
Turns an absolute URL or folder into one that's relative to the root of the
site. This is useful when turning a URL into a filesystem reference, or vice
versa.
Turns an absolute URL or folder into one that's relative to the root of the
site. This is useful when turning a URL into a filesystem reference, or vice
versa.
Parameters
- $url
string $url Accepts both a URL or a filesystem path
Returns
string Either a relative URL if the checks succeeded, or the original (possibly
absolute) URL.
|
public static
boolean
|
#
is_absolute( string $path )
Returns true if a given path is absolute. Works under both *nix and windows
systems
Returns true if a given path is absolute. Works under both *nix and windows
systems
Parameters
Returns
boolean
|
public static
boolean
|
#
is_absolute_url( string $url )
Checks if a given URL is absolute (e.g. starts with 'http://' etc.). URLs
beginning with "//" are treated as absolute, as browsers take this to mean the
same protocol as currently being used.
Checks if a given URL is absolute (e.g. starts with 'http://' etc.). URLs
beginning with "//" are treated as absolute, as browsers take this to mean the
same protocol as currently being used.
Useful to check before redirecting based on a URL from user submissions
through $_GET or $_POST, and avoid phishing attacks by redirecting to an
attackers server.
Note: Can't solely rely on PHP's parse_url() , since it is not intended to
work with relative URLs or for security purposes. filter_var($url,
FILTER_VALIDATE_URL) has similar problems.
Parameters
Returns
boolean
|
public static
boolean
|
|
public static
boolean
|
#
is_site_url( string $url )
Checks if the given URL is belonging to this "site" (not an external link).
That's the case if the URL is relative, as defined by Director::is_relative_url(),
or if the host matches Director::protocolAndHost().
Useful to check before redirecting based on a URL from user submissions
through $_GET or $_POST, and avoid phishing attacks by redirecting to an
attackers server.
Parameters
Returns
boolean
|
public static
string
|
#
getAbsFile( string $file )
Given a filesystem reference relative to the site root, return the full
file-system path.
Given a filesystem reference relative to the site root, return the full
file-system path.
Parameters
Returns
string
|
public static
|
#
fileExists( mixed $file )
Returns true if the given file exists.
Returns true if the given file exists.
Parameters
- $file
mixed $file Filename specified relative to the site root
|
public static
|
#
absoluteBaseURL( )
Returns the Absolute URL of the site root.
Returns the Absolute URL of the site root.
Used by
|
public static
|
#
absoluteBaseURLWithAuth( )
Returns the Absolute URL of the site root, embedding the current basic-auth
credentials into the URL.
Returns the Absolute URL of the site root, embedding the current basic-auth
credentials into the URL.
|
public static
boolean|string
|
#
forceSSL( mixed $patterns = null )
Force the site to run on SSL.
Force the site to run on SSL.
To use, call from _config.php. For example:
if(Director::isLive()) Director::forceSSL();
If you don't want your entire site to be on SSL, you can pass an array of
PCRE regular expression patterns for matching relative URLs. For example:
if(Director::isLive()) Director::forceSSL(array('/^admin/', '/^Security/'));
Note that the session data will be lost when moving from HTTP to HTTPS. It is
your responsibility to ensure that this won't cause usability problems.
CAUTION: This does not respect the site environment mode. You should check
this as per the above examples using Director::isLive() or Director::isTest()
for example.
Returns
boolean|string String of URL when unit tests running, boolean FALSE if patterns don't match
request URI
|
public static
|
#
forceWWW( )
Force a redirect to a domain starting with "www."
Force a redirect to a domain starting with "www."
|
public static
boolean
|
#
is_ajax( )
Checks if the current HTTP-Request is an "Ajax-Request" by checking for a
custom header set by prototype.js or wether a manually set request-parameter
'ajax' is present.
Checks if the current HTTP-Request is an "Ajax-Request" by checking for a
custom header set by prototype.js or wether a manually set request-parameter
'ajax' is present.
Returns
boolean
|
public static
boolean
|
#
is_cli( )
Returns true if this script is being run from the command line rather than
the webserver.
Returns true if this script is being run from the command line rather than
the webserver.
Returns
boolean
|
public static
|
#
set_environment_type( mixed $et )
Set the environment type of the current site.
Set the environment type of the current site.
Typically, a SilverStripe site have a number of environments: - development
environments, such a copy on your local machine. - test sites, such as the one
you show the client before going live. - the live site itself.
The behaviour of these environments often varies slightly. For example,
development sites may have errors dumped to the screen, and order confirmation
emails might be sent to the developer instead of the client.
To help with this, SilverStripe supports the notion of an environment type.
The environment type can be dev, test, or live.
You can set it explicitly with Director::set_environment_tpye(). Or you can
use Director::set_dev_servers() and Director::set_test_servers()
to set it implicitly, based on the value of $_SERVER['HTTP_HOST']. If the
HTTP_HOST value is one of the servers listed, then the environment type will be
test or dev. Otherwise, the environment type will be live.
Dev mode can also be forced by putting ?isDev=1 in your URL, which will ask
you to log in and then push the site into dev mode for the remainder of the
session. Putting ?isDev=0 onto the URL can turn it back.
Test mode can also be forced by putting ?isTest=1 in your URL, which will ask
you to log in and then push the site into test mode for the remainder of the
session. Putting ?isTest=0 onto the URL can turn it back.
Generally speaking, these methods will be called from your _config.php
file.
Once the environment type is set, it can be checked with Director::isDev(), Director::isTest(), and Director::isLive().
Parameters
- $et
mixed $et string The environment type: dev, test, or live.
|
public static
string
|
|
public static
|
#
set_dev_servers( mixed $servers )
Specify HTTP_HOST values that are development environments. For information
about environment types, see Director::set_environment_type().
CAUTION: Domain information can easily be spoofed in HTTP requests, we
recommend to set this mode via Director::set_environment_type() or an
_ss_environment.php instead.
Deprecated
3.0 Use Director::set_environment_type() or an _ss_environment.php instead.
Parameters
- $servers
mixed $servers array An array of HTTP_HOST values that should be treated as
development environments.
|
public static
|
#
set_test_servers( mixed $servers )
Specify HTTP_HOST values that are test environments. For information about
environment types, see Director::set_environment_type().
CAUTION: Domain information can easily be spoofed in HTTP requests, we
recommend to set this mode via Director::set_environment_type() or an
_ss_environment.php instead.
Deprecated
3.0 Use Director::set_environment_type() or an _ss_environment.php instead.
Parameters
- $servers
mixed $servers array An array of HTTP_HOST values that should be treated as test
environments.
|
public static
|
|
public static
|
#
isDev( mixed $dontTouchDB = false )
This function will return true if the site is in a development environment.
For information about environment types, see Director::set_environment_type().
Parameters
- $dontTouchDB
mixed $dontTouchDB If true, the database checks are not performed, which allows
certain DB checks to not fail before the DB is ready. If false (default), DB
checks are included.
|
public static
|
|
public static
array
|
#
get_template_global_variables( )
Returns
array Returns an array of strings of the method names of methods on the call that
should be exposed as global variables in the templates.
Implementation of
|
Comments
Use the Silverstripe Forum to ask questions.