employee
for our app../ └── myapp/ ├── src/ | ├── controller.app.php | └── controller.login.php ├── css/ ├── js/ └── index.phpIn this example we place the php code inside a
src
folder where it can be jailed away from the public using a simple .htaccess
file under Apache. See our .htaccess recommendations to secure your app.index.php
or a app.php
file. In reality it can have any name. For the purpose of this guide we will use the file index.php
.<?PHP require_once('../exc/exc.php'); //include EXC \exc\bootloader::run(); //load EXCThe line
require_once('../exc/exc.php')
includes EXC. Make sure you use the correct path to the "exc.php" file. In this example the file is located in a folder named exc
\exc\bootloader::run();
is what starts EXC and runs your application.controller.app.php
and place in your src
folder. In this file we will add our appController
class like this one:<?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 } } ?>
config()
in your appController
is a message handler that will be called to configure your application.
The configuration options are explained in detail here.<?php class appController extends \exc\controller\appController { public function config(){ $options = [ 'uid' => "ACMEEMP"; //our app identifier, every app needs an identifier... ]; return $options; } } ?>In our config handler we return an array of options. In this example we identify our application by assigning a
uid
.viewController
, services and CLI applications use the processController
. You will create instances of one of these to implement your app.viewController
for an employee record, our controller will be named "record".controller.record.php
in our src
folder.viewController
like this:class recordController extends \exc\controller\viewController { public function initialize(){ //this is called when EXC creates the instance of your controller } public function onAction_main(){ //this is our default action } public function onAction_show(){ //show our employee record... } public function unhandled($msg){ //message not implemented error_log('[ACME EMPLOYEE APP] MESSAGE [' . $msg . '] NOT IMPLEMENTED'); } }
on
+ message_name
.appInit
will be published, to handle the appInit
event we just add the function onAppInit
to our controller.public function onAppInit(){ //this is a message function //this function will be executed when an ```appInit``` message is published }See the section on events to learn more on the different messages that EXC will publish and how to publish your own.
client
(frontend) can request an action from your backend controller, lets said the action showRecord
to show an employee record. TO handle this action request we will simply add this event function:
public function onShowRecord(){ //my code here... }
NOTE An action name is case insensitive, therefor
showRecord
andshowrecord
are the same.
view.myname.php
, where myname
is the actual name of your view.views
in your app folder.