mvcControllerBase

Abstract mvcControllerBase class that all controllers inherit from. Provides base functionality for the MVC system. This class allows shared logic to be implemented at the very base level of a site e.g. authentication.

The class requires a concrete implementation, but usually has at least one intermediary class before a final controller e.g.

mvcControllerBase -> mvcController -> myController

Where mvcController is a site specific super-type controller that implements the main initialisation and authentication logic.

Scorpio uses a mvcControllerBase::launch() method for handling the request processing. This makes the controllers more like PageControllers than a typical web controller / command; however you are free to implement method handling if you wish. The mvcControllerBase::isValidAction() is abstract for this very reason - how you dispatch the actions is up to you.


Methods

public __construct($inRequest, [$inResponse = null])

Returns new mvcControllerBase instance

If overloading __construct, ensure that the first argument is always an instance of mvcRequest. Additional arguments can be added after this. Place custom configuration code inside the mvcControllerBase::initialise() method. Initialise is always called after the request has been set to the controller object.

public reset()

Rests object to defaults

public abstract initialise()

Perform pre-launch set-up for this controller, including setting the default action

public abstract isValidAction()

Returns true if the parsed action is valid for this controller

public abstract isValidView($inView)

Returns true if the requested view can be used with this controller

public abstract isAuthorised()

Returns true if requester is authorised for this controller

public abstract authorise()

Handle the authorisation requests or redirect to component that will

public abstract hasAuthority($inActivity)

Returns true if the user has authority to access/use $inActivity

public abstract launch()

Launch the actions of the controller

public redirect($inLocation)

Redirects the browser to $inLocation in a semi-intelligent fashion. If headers are already sent displays the static template page "redirect.XYZ" where XYZ is the current output type e.g. xml, html, wml

The redirect template should contain %redirect.location% as a link for the user to follow. It will be replaced with whatever link was passed into redirect().

public controllerRedirect($inController, $inAction, $inPath)

Redirects to a specific controller in the request controller map

This method will forward a request to another controller within the same request context i.e. without any additional HTTP overheads. This requires an amount of setting up as the controller must reside within the controller map and the mvcRequest object requires updating with any additional data to forward to the called controller.

An example usage would be to forward requests to a login controller when a request has not been verified, or if additional processing is required on a previously successful action.

The basics are to call the controller (without suffix e.g. loginController is called as "login"), with the required action (that must be valid on that controller) and the path to this controller as it would be requested via the normal route. The path is important as it will re-configure the mvcRequest data structures for this new request and cause all subsequent links to resolve correctly (similar to {@link mvcViewBase::getControllerView})

class myController extends mvcController {

    function launch() {
       // do something and process some stuff through the model
       // now instead of forwarding to a view, redirect

       $this->controllerRedirect('another', 'doMoreProcessing', '/path/to/another');
       // no more code will be executed after this point; the request will be processed
       // by "anotherController" located in the controllers folder in /path/to/another/
    }
}

public addInputFilters()

Binds input filters to the input manager; called in initialise()

class controller extends mvcController {

    // bind input filters
    function addInputFilters() {
        $this->getInputManager()->addInputFilter('someVar', utilityInputFilter::filterString());
    }
}

public validateInputData($inData)

Performs additional validation on the input data, returns true if OK, or an error string

public addInputToModel($inData, $inModel)

Maps filtered input data to the controller model

public fetchStandaloneView([$params = array()])

Returns the standalone view based on the params.

This method is called from within a view (usually from mvcViewBase::getControllerView()). The array of parameters includes:

$params will also contain any passed parameters that were defined in the view.

public isModified()

Returns $_Modified

public setModified([$inModified = true])

Set $_Modified to $inModified

public getAction()

Returns the current action that is being requested

public setAction($inAction)

Set the current action for the request

public getDefaultAction()

Returns a default action

public setDefaultAction($inDefaultAction)

Set the default action for the controller, usually defined in the initialise call

public getActionFromRequest([$inDefault = ''], [$inLevel = 0])

Fetches data from the request URI string

This method allows data to be encoded in the URI string and then used during the request processing, allowing for SEO friendly URIs. $inDefault specifies a value to use if the section cannot be found and $inLevel is how far up the URI string to fetch the value from. The level is offset by the current controller level as determined by the mvcControllerMapper.

As an example: /product/view/123456/My_Product_Name

function launch() {
    $prodID = $this->getActionFromRequest(false, 1);
    // prodID is 123456
}

public getInputManager()

Returns the instance of the utilityInputManager

public setInputManager($inInputManager)

Set a pre-built input manager instance

public getModel()

Returns $_Model

public setModel($inModel)

Set $_Model to $inModel

public getRequest()

Returns the current mvcRequest

public setRequest($inMvcRequest)

Set $_MvcRequest to $inMvcRequest

public getResponse()

Returns $_MvcResponse

public setResponse($inMvcResponse)

Set $_MvcResponse to $inMvcResponse

public getRequiresAuthentication()

Returns true if the controller requires authentication

public setRequiresAuthentication($inRequiresAuthentication)

Set whether the controller requires authentication (true) or not (false)

public getClassName()

Returns the current class name

public getControllerLevel()

Returns the current level this controller is at in the request; 0 is root

public getSubControllers()

Returns array of sub controllers for this controller

public getControllerActions()

Return ControllerActions

public getControllerViews()

Returns ControllerViews

public buildUriPath([$inAction = null], [$inData = null])

Builds a URI for this controller with optional action and data; both should be strings

<  1  >