Comments: on this page. Click to read or post your own.

Class Controller

Description

Base controller class.

Controllers are the cornerstone of all site functionality in Sapphire. The Director selects a controller to pass control to, and then calls run(). This method will execute the appropriate action - either by calling the action method, or displaying the action's template.

See getTemplate() for information on how the template is chosen.

Located in /sapphire/core/control/Controller.php (line 12)

Object
   |
   --ViewableData
      |
      --RequestHandler
         |
         --Controller
Direct descendents
Class Description
Upload Manages uploads via HTML forms processed by PHP, uploads to Silverstripe's default upload directory, and either creates a new or uses an existing File-object for syncing with the database.
ControllerTest_Controller Simple controller for testing
ControllerTest_SecuredController Controller with an $allowed_actions value
RequestHandlingTest_Controller Controller for the test
RequestHandlingTest_AllowedController Controller for the test
TableFieldTest_Controller Stub controller
FormTest_Controller Base controller class.
TableListFieldTest_TestController Base controller class.
RestfulServiceTest_Controller Base controller class.
CliController Base class invoked from CLI rather than the webserver (Cron jobs, handling email bounces).
Security Implements a basic security model
DevelopmentAdmin Base class for URL access to development tools. Currently supports the ; and TaskRunner.
JSTestRunner Controller that executes QUnit tests via jQuery.
SapphireREPL Base controller class.
TaskRunner
ModelViewer Gives you a nice way of viewing your data model.
SapphireInfo Returns information about the current site instance.
CodeViewer Allows human reading of a test in a format suitable for agile documentation
InstallerTest Simple controller that the installer uses to test that URL rewriting is working.
TestViewer Allows human reading of a test in a format suitable for agile documentation
TestRunner Controller that executes PHPUnit tests.
ReportField_Controller This class instantiates an instance of the report field and receives ajax requests to the report field.
ContentController The most common kind of controller; effectively a controller linked to a DataObject.
RootURLController This controller handles what happens when you visit the root URL.
ModelAsController ModelAsController will hand over all control to the appopriate model object It uses URLSegment to determine the right object. Also, if (ModelClass)_Controller exists, that controller will be used instead. It should be a subclass of ContentController.
DatabaseAdmin DatabaseAdmin class
Image_Uploader Uploader support for the uploading anything which is a File or subclass of File, eg Image.
Email_BounceHandler Base class that email bounce handlers extend
VersionedRestfulServer Simple wrapper to allow access to the live site via REST
RestfulServer
SapphireSoapServer Soap server class.
WidgetFormProxy
Widget_Controller Base controller class.
LeftAndMain LeftAndMain is the parent class of all the two-pane views in the CMS.
CMSHelp Base controller class.
ImageEditor This Controller handles all operation needed for ImageEditor to work(expect for GD operations).
StaticExporter This class lets you export a static copy of your site.
ModelAdmin_CollectionController Handles a managed model class and provides default collection filtering behavior.
ModelAdmin_RecordController Handles operations on a single record from a managed model.
PageComment_Controller Base controller class.
BatchProcess_Controller Base controller class.
RebuildStaticCacheTask
SiteTreeMaintenanceTask
OrderReport_Popup This is a stand-alone controller, designed to be used with the eCommerce reporting system.
WorldpayPayment_Handler Handler for responses from the WorldPay site
PayPalPayment_Handler Handler for responses from the PayPal site
PaystationHostedPayment_Handler Handler for responses from the PayPal site
ShoppingCart_Controller Base controller class.
Variable Summary
Method Summary
static Controller curr ()
static boolean has_curr ()
static void join_links ()
void AbsoluteLink ()
boolean can (perm $perm, [member $member = null])
void CurrentMember ()
void defaultAction ( $action)
void getAction ()
void getFormOwner ()
void getResponse ()
array getURLParams ()
SSViewer getViewer ( $action)
void handleAction ( $request)
void handleRequest (HTTPRequest $request)
void init ()
boolean isAjax ()
Date Now ()
boolean PastMember ()
boolean PastVisitor ()
void popCurrent ()
void pushCurrent ()
void redirect ( $url, [ $code = 302])
void redirectBack ()
string redirectedTo ()
string render ([array $params = null])
void setSession (Session $session)
void setURLParams ( $urlParams)
Variables
static mixed $controller_stack = array() (line 44)

Stack of current controllers.

Controller::$controller_stack[0] is the current controller.

  • access: protected
static mixed $url_handlers = array(
'$Action//$ID/$OtherID' => 'handleAction',
)
(line 63)

Default URL handlers - (Action)/(ID)/(OtherID)


Redefinition of:
RequestHandler::$url_handlers
The default URL handling rules. This specifies that the next component of the URL corresponds to a method to be called on this RequestHandlingData object.

Redefined in descendants as:
string $action (line 33)
  • var: The URL part matched on the current controller as determined by the "$Action" part of the $url_handlers definition. Should correlate to a public method on this controller. Used in render() and getViewer() to determine action-specific templates.
  • access: protected
mixed $baseInitCalled = false (line 212)
  • access: protected
mixed $basicAuthEnabled = true (line 46)
  • access: protected
HTTPRequest $request (line 58)
  • var: The request object that the controller was called with. Set in handleRequest(). Useful to generate the {}
  • access: protected

Redefinition of:
RequestHandler::$request
array $requestParams (line 24)
  • var: Contains all GET and POST parameters passed to the current HTTPRequest.
  • access: protected
  • uses: HTTPRequest->requestVars()
HTTPResponse $response (line 52)
  • var: The response object that the controller returns. Set in handleRequest().
  • access: protected
mixed $session (line 38)

The Session object for this controller

  • access: protected
array $urlParams (line 17)
  • var: An array of arguments extracted from the URL
  • access: protected

Inherited Variables

Inherited from ViewableData

ViewableData::$casting
ViewableData::$castingHelperPair_cache
ViewableData::$customisedObj
ViewableData::$failover
ViewableData::$iteratorPos
ViewableData::$iteratorTotalItems
ViewableData::$namedAs
ViewableData::$parent
ViewableData::$_natural_cache
ViewableData::$_object_cache
ViewableData::$_xml_cache

Inherited from Object

Object::$class
Object::$extensions
Object::$extension_instances
Methods
static method curr (line 343)

Returns the current controller

  • access: public
static Controller curr ()
static method has_curr (line 355)

Tests whether we have a currently active controller or not

  • return: True if there is at least 1 controller in the stack.
  • access: public
static boolean has_curr ()
static method join_links (line 532)

Joins two link segments together, putting a slash between them if necessary.

Use this for building the results of Link() methods.

If either of the links have query strings, then they will be combined and put at the end of the resulting url.

static void join_links ()
AbsoluteLink (line 391)

Returns an absolute link to this controller

void AbsoluteLink ()
can (line 366)

Returns true if the member is allowed to do the given action.

boolean can (perm $perm, [member $member = null])
  • perm $perm: The permission to be checked, such as 'View'.
  • member $member: The member whose permissions need checking. Defaults to the currently logged in user.
CurrentMember (line 398)

Returns the currently logged in user

void CurrentMember ()

Redefinition of:
ViewableData::CurrentMember()
Returns the currently logged in user.
defaultAction (line 266)

This is the default action handler used if a method doesn't exist.

It will process the controller object with the template returned by getViewer()

void defaultAction ( $action)
  • $action
disableBasicAuth (line 335)

Call this to disable basic authentication on test sites.

must be called in the init() method

  • deprecated: Use BasicAuth::disable() instead? This is used in CliController - it should be updated.
void disableBasicAuth ()
getAction (line 273)

Returns the action that is being executed on this controller.

void getAction ()
getFormOwner (line 247)

Return the object that is going to own a form that's being processed, and handle its execution.

Note that the result needn't be an actual controller object.

void getFormOwner ()

Redefined in descendants as:
getRequest (line 208)

Get the request with which this controller was called (if any).

Usually set in handleRequest().

HTTPRequest getRequest ()

Redefinition of:
RequestHandler::getRequest()
Returns the HTTPRequest object that this controller is using.
getResponse (line 198)

Returns the HTTPResponse object that this controller is building up.

Can be used to set the status code and headers

void getResponse ()
getSession (line 504)

Get the Session object representing this Controller's session

Session getSession ()
getURLParams (line 190)
  • return: The parameters extracted from the URL by the Director.
array getURLParams ()
getViewer (line 281)

Return an SSViewer object to process the data

  • return: The viewer identified being the default handler for this Controller/Action combination
SSViewer getViewer ( $action)
  • $action
handleAction (line 149)

Controller's default action handler. It will call the method named in $Action, if that method exists.

If $Action isn't given, it will use "index" as a default.

void handleAction ( $request)
  • $request
handleRequest (line 104)

Handles HTTP requests.

If you are going to overload handleRequest, make sure that you start the method with $this->pushCurrent() and end the method with $this->popCurrent(). Failure to do this will create weird session errors.

void handleRequest (HTTPRequest $request)
  • $request $request: The HTTPRequest object that is responsible for distributing request parsing.

Redefinition of:
RequestHandler::handleRequest()
Handles URL requests.

Redefined in descendants as:
init (line 77)

Initialisation function that is run before any action on the controller is called.

void init ()

Redefined in descendants as:
isAjax (line 519)

Returns true if this controller is processing an ajax request

  • return: True if this controller is processing an ajax request
boolean isAjax ()
Now (line 382)

returns a date object for use within a template

Usage: $Now.Year - Returns 2006

  • return: The current date
Date Now ()
PastMember (line 415)

Return true if the visitor has signed up for a login account before

boolean PastMember ()
PastVisitor (line 406)

Returns true if the visitor has been here before

boolean PastVisitor ()
popCurrent (line 439)

Pop this controller off the top of the stack.

void popCurrent ()
pushCurrent (line 424)

Pushes this controller onto the stack of current controllers.

This means that any redirection, session setting, or other things that rely on Controller::curr() will now write to this controller object.

void pushCurrent ()
redirect (line 451)

Redirct to the given URL.

It is generally recommended to call Director::redirect() rather than calling this function directly.

void redirect ( $url, [ $code = 302])
  • $url
  • $code
redirectBack (line 474)

Redirect back. Uses either the HTTP_REFERER or a manually set request-variable called _REDIRECT_BACK_URL.

This variable is needed in scenarios where not HTTP-Referer is sent ( e.g when calling a page by location.href in IE). If none of the two variables is available, it will redirect to the base URL (see Director::baseURL()).

void redirectBack ()
redirectedTo (line 496)

Tests whether a redirection has been requested.

  • return: If redirect() has been called, it will return the URL redirected to. Otherwise, it will return null;
string redirectedTo ()
render (line 319)

Render the current controller with the templates determined by getViewer().

  • return: Parsed template content
string render ([array $params = null])
  • array $params: Key-value array for custom template variables (Optional)
setSession (line 511)

Set the Session object.

void setSession (Session $session)
setURLParams (line 183)
void setURLParams ( $urlParams)
  • $urlParams

Inherited Methods

Inherited From RequestHandler

RequestHandler::checkAccessAction()
RequestHandler::getRequest()
RequestHandler::handleRequest()
RequestHandler::httpError()

Inherited From ViewableData

ViewableData::ATT_val()
ViewableData::BaseHref()
ViewableData::buildCastingHelperCache()
ViewableData::cachedCall()
ViewableData::castingHelper()
ViewableData::castingHelperPair()
ViewableData::castingObjectCreator()
ViewableData::castingObjectCreatorPair()
ViewableData::CSSClasses()
ViewableData::CurrentMember()
ViewableData::CurrentPage()
ViewableData::customise()
ViewableData::Debug()
ViewableData::defineMethods()
ViewableData::escapeTypeForField()
ViewableData::Even()
ViewableData::EvenOdd()
ViewableData::First()
ViewableData::FirstLast()
ViewableData::getField()
ViewableData::getIterator()
ViewableData::getXMLValues()
ViewableData::hasField()
ViewableData::HasPerm()
ViewableData::hasValue()
ViewableData::i18nLocale()
ViewableData::IsAjax()
ViewableData::iteratorProperties()
ViewableData::JS_val()
ViewableData::Last()
ViewableData::Me()
ViewableData::Middle()
ViewableData::MiddleString()
ViewableData::obj()
ViewableData::Odd()
ViewableData::Pos()
ViewableData::RAW_val()
ViewableData::renderWith()
ViewableData::SecurityID()
ViewableData::setCustomisedObj()
ViewableData::setField()
ViewableData::SQL_val()
ViewableData::ThemeDir()
ViewableData::Top()
ViewableData::TotalItems()
ViewableData::val()
ViewableData::XML_val()
ViewableData::__get()
ViewableData::__isset()
ViewableData::__set()

Inherited From Object

Object::__construct()
Object::addMethodsFrom()
Object::addStaticVars()
Object::addWrapperMethod()
Object::add_extension()
Object::add_static_var()
Object::allMethodNames()
Object::buildMethodList()
Object::cacheToFile()
Object::cacheToFileWithArgs()
Object::clearCache()
Object::combined_static()
Object::create()
Object::createMethod()
Object::defineMethods()
Object::exists()
Object::extend()
Object::extInstance()
Object::getCustomClass()
Object::get_static()
Object::hasExtension()
Object::hasMethod()
Object::has_extension()
Object::invokeWithExtensions()
Object::is_a()
Object::loadCache()
Object::parentClass()
Object::remove_extension()
Object::sanitiseCachename()
Object::saveCache()
Object::set_stat()
Object::set_static()
Object::set_uninherited()
Object::stat()
Object::strong_create()
Object::uninherited()
Object::uninherited_static()
Object::useCustomClass()
Object::__call()
Object::__toString()
blog comments powered by Disqus

Documentation generated on Mon, 23 Mar 2009 06:47:27 +1300 by phpDocumentor 1.3.2