Quince PHP Controller


Starting the Controller

<?php

$controller 
= new Quince();

?>

The Dispatch

The dispatch() method of the controller is called automatically unless you disable the automatic dispatch by passing it a false value as a second argument.

<?php

$controller 
= new Quince('config/controller.xml'false);
$controller->dispatch();

?>

When Quince dispatches, it will try to detect if the XML file you specify has been modified since it last parsed it. If it has, Quince will automatically re-load it, which adds about 10ms on most production servers, depending on the size and complexity of the file, and the speed of the server. If cookies or sessions are disabled, the XML file will need to be loaded for every request.

The dispatch will collect all modules, aliases, namespaces, and form-forwards from the XML file, and will parse the current request URL in order to try and work out which module should be loaded, and which method should be called.

If you disable the automatic dispatch, you can call the method manually at a later moment of your choosing. This feature is useful if you want to change one or more of the advanced settings, such as prefixing class methods. Automatic mode is enabled by default for compatibility with prior versions.

There are a wide array of information-retrieving methods that can be called once the dispatch has been run:

String getModuleName() String getMethodName() String getClassName() String getTemplateName() string getDomain() String getRequest() String getUrlFor($module, $method, $args) Bool getIsAlias()

Calling The Action

To execute the method that is associated with the current URL and access the result, all you need are these two expressions (assuming the dispatch has already been called).

<?php

$controller
->performAction();
$content $controller->getContent();
$logEvents $controller->getDebugContent(Quince::E_ALL);

?>

$content will contain whatever your function returned.

$logEvents, unsurprisingly, will contain a detailed log of everything that happened from initialisation to that point where you retrieve it.

Returning Built-In Constants

There are constants you can return, and later check for, that you can use to alter the display of your user interface:

Quince::FAIL
Your function can return this constant if there was some problem with the operation it attempted to carry out.

<?php

$controller
->performAction();
$content $controller->getContent();

if(
$content == Quince::FAIL){
    
// display error template
}else{
    
// display normal template
}

?>

Quince::NODISPLAY
Your function can return this constant if nothing is to be displayed, and then your front controller can check for its value in any content that gets returned.

<?php

$controller
->performAction();
$content $controller->getContent();

if(
$content != Quince::NODISPLAY){
    
// display template
}

?>