[commits] [Wiki] created: Doc/Dev/Horde_Controller

Ralf Lang (B1 Systems GmbH) lang at b1-systems.de
Tue Aug 6 18:10:17 UTC 2013


rlang  Tue, 06 Aug 2013 18:10:17 +0000

Created page: http://wiki.horde.org/Doc/Dev/Horde_Controller

[toc]]

+ Horde_Controller

Documentation on using Horde_Controller

++ General Info

++ Horde_Controllers in Horde Core Apps

Horde Controllers are independent from the Horde Ajax Framework.
Controllers need Horde_Routes and need rewrite rules.

Ajax application controllers do not live in lib but in
$app/app/controllers/

Example:

class Nag_CompleteTask_Controller in nag/app/controllers/CompleteTask.php
<code>
<?php
class Nag_CompleteTask_Controller extends Horde_Controller_Base
{
     public function processRequest(Horde_Controller_Request $request,  
Horde_Controller_Response $response)
     {
         /* Toggle the task's completion status if we're provided with a
          * valid task ID. */
         $requestVars = $request->getRequestVars();
         if (isset($requestVars['task']) && isset($requestVars['tasklist'])) {
             $nag_task = new Nag_CompleteTask();
             $result = $nag_task->result($requestVars['task'],  
$requestVars['tasklist']);
         } else {
             $result = array('error' => 'missing parameters');
         }

         $requestVars = $request->getGetVars();
         if (!empty($requestVars['format']) &&
             $requestVars['format'] == 'json') {
             $response->setContentType('application/json');
             $response->setBody(json_encode($result));
         } elseif ($requestVars['url']) {
             $response->setRedirectUrl($requestVars['url']);
         }
     }
}
?>
</code>



A Horde Controller based app needs a config/routes.php file.

For example
<code>
<?php
/**
  * Setup default routes
  */
$mapper->connect('/t/complete',
     array(
         'controller' => 'CompleteTask',
     ));
?>
</code>

defines a route for a call like www.myhorde.de/nag/t/complete to be  
handled by the CompleteTask controller seen above.

The endpoint script is horde/rampage.php  - rampage.php currently  
seems to handle only authenticated calls.

The controller is passed the request (in this case, a json request)  
and handles it (with a json answer in this case)




More information about the commits mailing list