appController
is the orchestrator of your application lifecycle. Every application must a have an instance of an appController
. To better understand this section you should read about controllers, if you haven't done so already.appController
. It is responsible for managing messages and events and sending the response.appController
class to handle your app's logic or you may have EXC create a generic instance for you.controller.app.php
. This file may be placed in your src
folder or in your application folder.
./ └── myapp/ └── src/ └── controller.app.phpYou may also place the class in your startup php file, or specify the path to your
src
folder in a constant named SRC_PATH
. For example in your index.php you can add:<?php define('SRC_PATH', __DIR__ . '/src/');
If EXC does not find an
appController
class it will create a generic instance of theappController
automatically.
appController
extends the built in controller \exc\controller\appController
which does the heavy lifting.<?php class appController extends \exc\controller\appController { public function config(){ //config our app... } public function initialize(){ error_log("--- @appController->initialize() ---"); } public function unhandled($msg){ //called when a message is not implemented error_log("@appController->unhandled ---- $msg"); } public function willDispatchAction($actionName){ //about to execute an action //we can change the action by returning a different action name here } } ?>In the
config()
message we setup different options. These options are explained here.initialize()
and unhandled()
are handlers for messages. To learn more check the controller documentation.appController
.<?php $app = \exc\app::controller();
<?php $app = \exc\controller\appController::instance();If you have a class that inherits from
viewController
or processController
you can use:
<?php $app = $myObject->appController();or inside a
viewController
or processController
as:
<?php $app = $this->appController();
appController
is used to publish events related to the execution of your app. In general we add event handlers to the appController
.appController
may have delegate controllers, which actually implement the behavior or execute your applications logic, these are called application controllers.viewController
or processController
that you create. See Adding your own controllers in this document for more information.appController
.appController
event by using it's on()
function.<?php $app = \exc\controller\appController::instance(); //get an instance of the app controller $app->on( 'appStart', $callback ); //register for the event appStart
\exc\core\controller
and \exc\core\base
.Instance Methods | Description |
---|---|
setOption(string $key, mixed $value) | Sets an application option. |
getDefaultView() | Returns the view instance designated as default view. Returns null if the default view is not set. |
setDefaultView(mixed $view) | Sets the default view. Parameters: `$view` A string with the name of the view or an instance of a view . |
client() | Returns the \exc\client instance. |
header(string $name, string $value) | Sets an HTTP header. |
end() | Terminates the application execution. |
abort() | Aborts the application execution. |
sendJSON(mixed $data) | Sends a JSON payload to the front-end. The parameter $data may be a hash of key-value pairs or a json encoded string. |
sendJS(string $code) | Sends valid a string with javascript code to the front-end. |
sendView(object $aView) | Sends the contents of a view to the front-end. |
write(string $data) | Appends the contents of $data to the output buffer. |
commit(string $payload) | Sends a payload to the front-end. |
sendDownloadWithData(string $mime, string $data, string $filename=null) | Sends $data as a file attachment. |
willDispatchAction(string $actionName) | Message EXC will dispatch a controller action. You may change the action to execute by returning a string with a different action name. |
canBecomeFirstResponder(string $controllerClassName, object $controllerInstance) | Message EXC will delegate the role of first responder to a given controller. Return false to deny the switch. |
Class Methods | Description |
---|---|
instance() | returns the global instance of the appController . |