mosController Class Reference

List of all members.

Public Member Functions

 __construct (mosRequest &$request, mosRenderer &$renderer, $commandname='command')
 run ()
 forward ($command)
 setCommand ($command)
 setView ($viewname)
 redirect ($url)

Private Attributes

 $commandname
 $command
 $view
 $request
 $renderer


Detailed Description

A controller class modelled on the front controller and application controller design patterns. The Command and View classess are an integral part of this pattern.

Definition at line 9 of file mosRenderer.php.


Constructor & Destructor Documentation

mosController::__construct ( mosRequest &$  request,
mosRenderer &$  renderer,
commandname = 'command' 
)

Constructor.

Parameters:
object $request - A reference to a request object
object $renderer - A reference to a renderer object
string $commandname - the name of the $_REQUEST variable containing the command name
Returns:
Controller

Definition at line 50 of file mosRenderer.php.

References $commandname.

00051     {
00052         $this->request     =& $request;
00053         $this->renderer    =& $renderer;
00054         $this->commandname =  $commandname;
00055     }


Member Function Documentation

mosController::run (  ) 

Forwards the request to the correct command from the request or the default command, Then forwards to a view.

Definition at line 62 of file mosRenderer.php.

References $_REQUEST, $command, forward(), and setView().

00063     {
00064         $command = $this->request->getParam($_REQUEST, $this->commandname, 'default');
00065         $this->forward($command);
00066         // get the view from the command
00067         $this->setView($this->command->getView());
00068         $this->view->render($this->request, $this->renderer);
00069     }

mosController::forward ( command  ) 

sets the current command object and calls its execute method

Parameters:
unknown_type $command

Definition at line 76 of file mosRenderer.php.

References $command, and setCommand().

Referenced by run().

00077     {
00078         $this->setCommand($command);
00079         $this->command->execute($this, $this->request);
00080     }

mosController::setCommand ( command  ) 

Instantiates the command class and sets the current command property. The command classes must extend the Command class and must follow a naming convention. eg. the 'addUser' command class must be named 'addUserCommand'

Parameters:
string $command
Returns:
bool - triggers an error if the command class isn't found.

Definition at line 90 of file mosRenderer.php.

References $command.

Referenced by forward().

00091     {
00092         $commandclass = $command.'Command';
00093         // instantiate the command class
00094         if (class_exists($commandclass)) {
00095             $this->command = new $commandclass();
00096         } else {
00097             return trigger_error("Command class '$commandclass' not found.", E_USER_ERROR);
00098         }
00099     }

mosController::setView ( viewname  ) 

Instantiates the view class and sets the current view property The view classes must extend the View class and must follow a naming convention. The view is also associated to the command that sets it. eg. the form view for the 'addUser' command class must be named 'form_addUserView'

Parameters:
string $viewname - the view name st by the command
Returns:
bool - triggers an error if the view class isn't found.

Definition at line 109 of file mosRenderer.php.

References $commandname.

Referenced by run().

00110     {
00111         $commandname = substr(get_class($this->command), 0, -7);
00112         $viewclass = $viewname.'View';
00113         if (class_exists($viewclass)) {
00114             $this->view = new $viewclass();
00115         } else {
00116             return trigger_error("View class '$viewclass' not found.", E_USER_ERROR);
00117         }
00118     }

mosController::redirect ( url  ) 

Helper function to redirect the user request. useful for cases where we don't want the user to resend a form

Parameters:
unknown_type $url

Definition at line 125 of file mosRenderer.php.

00126     {
00127         if (headers_sent()) {
00128             echo "<script>document.location.href='$url';</script>";
00129         } else {
00130             if (ob_get_contents()) while (@ob_end_clean()); // clear output buffer if one exists
00131             header( "Location: $url" );
00132         }
00133         exit;
00134     }


Member Data Documentation

mosController::$commandname [private]

Definition at line 16 of file mosRenderer.php.

Referenced by __construct(), and setView().

mosController::$command [private]

Definition at line 22 of file mosRenderer.php.

Referenced by forward(), run(), and setCommand().

mosController::$view [private]

Definition at line 28 of file mosRenderer.php.

mosController::$request [private]

Definition at line 34 of file mosRenderer.php.

mosController::$renderer [private]

Definition at line 40 of file mosRenderer.php.


The documentation for this class was generated from the following file:

Generated on Wed May 14 13:02:01 2008 for ALIRO by  doxygen 1.5.5