mvcViewBase

mvcViewBase class that all views inherit from. Includes the rendering engine setup routines. This class is extended by all views within the mvc system.

The template engine can be exchange so long as an appropriate adaptor is created to route the various requests to the template engine. Two engines are included: Smarty and a generic PHP system. The engine to be used can be defined in the site config.xml file. Generally once an engine has been decided upon it cannot be easily changed due to vast differences in template code e.g. Smarty vs. straight PHP vs. PHPTal etc.

When passing variables through to the view system, they should be encapsulated using the output wrapper. This blocks attempts to modify objects and helps to protect the models from being changed. See utilityOutputWrapper for more details.

mvcViewBase supports "resources". These are additional files to be used with the templates. Currently this is limited to CSS and Javascript. During the render phase, additional CSS and Javascript files or code can be added and injected into the template. This requires that the template be set-up to output this information.

Views can be executed via two methods:

  1. Direct rendering
  2. Compilation

Direct rendering, as the name implies will compile and render to the current requestor any response. This is the default response from a view. Headers will be sent during this method call, including any headers defined by the view engine.

Compilation uses the template engine to compile the response, but it is returned instead of being displayed. This allows the response to be further filtered or to be included in other output.

Compilation is used for rendering controller views.


Methods

public __construct($inController)

Returns new mvcViewBase instance

public __call($name, $arguments)

Redirects unknown calls to the view helper system

public setupEngine()

Setups up the Engine environment for us

public setupInitialVars()

Assigns some default values to template engine that are always needed

public disableTemplateCache()

Used to disable template caching

public setCacheLevelNone()

Disable template caching completely

public setCacheLevelLow()

Set the template cache time to "low" (10 minutes)

public setCacheLevelMedium()

Set the template cache to a medium level (1 hour)

public setCacheLevelHigh()

Set the template cache to a high level (5 hours)

public setCacheLevelPersist()

Essentially persist the template (caches for 1 whole day)

public getTemplateFile($inFileName, [$inPath = null])

Locate the requested template from the file system, throws exception if not found

public getTpl($inFileName, [$inPath = null])

Return a statically cached template or add it if it is not there

public getControllerView([$inControllerName = null], [$inControllerPath = null], [$inView = null], [$inParams = null])

Fetches a view from a different controller. The path is the controllerMap path (URI path) to the controller. The view must be named in the controller and be permitted by the mvcControllerViews system (see motdController.class.php for an example in baseAdminSite). $inControllerName is the controller name without the "Controller" suffix.

Use this method within your templates. It can be used in place of the Smarty function smarty_function_includeView to allow other template engines to pull in external views.

$inParams is a string of the parameters formatted like a URI request string, for example:

$inParams = 'param1=value1¶m2=val2&3=4';

This string will be converted to an array and passed to the requested controllers mvcControllerBase::fetchStandaloneView() method. Additionally, the parameters will contain: controller, view, classname and path.

	// in php templates
 $oView->getControllerView('motd', '/controlPanel/systemTools/motd', 'motd');

 // smarty
 {$oView->getControllerView('motd', '/controlPanel/systemTools/motd', 'motd')}

 // with additional parameters
 {$oView->getControllerView('motd', '/controlPanel/systemTools/motd', 'motd', 'param1=value1¶m2=value2')}

public getEngine()

Returns mvcViewEngineBase object

public sendHeaders()

Sends any set headers to the browser, only if headers have not already been sent

public render($inTemplate, [$inCacheID = null], [$inCompileID = null])

Displays the view output generated from the request via the template layer

public compile($inTemplate, [$inCacheID = null], [$inCompileID = null])

Executes and compiles the response, but returns rather displays the results

public isCached($inTemplate, [$inCacheID = null], [$inCompileID = null])

test to see if valid cache exists for this template

public getCacheId($inCacheId)

Adjusts $inCacheId to reflect the request locale, port and mobile device output type

public getController()

Returns the current controller for this view

public setController($inController)

Set the controller object

public getRequest()

Returns the mvcRequest object

public getResponse()

Returns the mvcResponse object

public getModel()

Returns the model

public getViewHelperFactory()

Returns the view helper factory instance

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

Builds a valid path to the the action $inAction with optional data $inData

$inAction should be an action that is valid for the current controller. $inData should be url_encoded or be in a URI friendly state.

public getHeaders()

Returns the current set of headers to be used during output

public addHeader($inType, $inValue)

Add a header to the set, will overwrite an existing header

public removeHeader($inType)

Removes the specified header from the set

public addCssResource($inResource)

Adds a CSS resource

public addJavascriptResource($inResource)

Adds a Javascript resource

public addMetaResource($inResource)

Adds a Meta resource

public addResource($inResource)

Adds an mvcViewResource

public removeResource($inResource)

Removes the resource

public getResourceByIdentifier($inResource)

Locates a resource by the identifier, returns null if not found

public getResourcesByType($inType)

Returns the set of resources by type

public getResourceType($inResource)

Returns the resource type from the specified resource object

<  1  >