<?php $client = \exc\client::instance();
$client
to make common interactions with your client easily.## The shared session ## {#shrdsess}Note: Most methods of
$client
are chainable. Examples here do not use chaining for sake of simplicity.
## Setting a key ## {#shrdkeyset}For security reasons the server always overrides the session values on the client.
<?php $client->session($key, $value);## Getting the value of a key ## {#shrdkeyget}
<?php $value = $client->session($key);## Testing if a key exists ## {#shrdkeytest}
<?php $ok = $client->sessionHasKey($key);## Removing a key ## {#shrdkeyrm}
<?php $client->sessionRemove($key);## Publish a message or event ## {#pubmsg}
<?php $client->publish("displayRecord", ["id"=>20]);## Adding a javascript file ## {#addjsfile}
<?php $client->addJSFile($aPath); $client->addJSFile('asset://js/myfile.js'); //may use exc's special url protocols## Adding a css file ## {#addcssfile}
<?php $client->addCSSFile($aPath); $client->addCSSFile('asset://css/mystyle.css'); //may use exc's special url protocols## Adding a javascript controller file ## {#addjscontroller}
<?php $client->addController($objectName, $aPath); $client->addController('recordController', 'asset://js/controller.record.js'); //may use exc's special url protocols## Set application data ## {#appdataset}
<?php $aValue = ["id"=>25, "name"=>"Jose", "lname"=>"Cuevas"]; $client->setData("record", $aValue);
## Respond to a request ## {#apprespset}Data is available in your front-end using the property
app.data
, for exampleapp.data.record.name
.
$client->sendResponseData($data)
to send the data. Lets see a very simple example:<?php class appController extends \exc\controller\viewController { public function onAction_ComputeRate(){ $client = \exc\client::instance(); $qty = $client->values['qty']; $results = ["status"=>200, "cost"=>25 * $qty, "qty"=>$qty]; $client->sendResponseData($results); $client->done(); //finish the interaction }In our front-end we invoke our service using a backend action.
var action = exc.backend.action("@(app.computeRate)"); //create a backend action action.params.qty = 2; //set a parameter action.exec().then(function(data){ alert("The cost is:" + data.cost); });## Run javascript code ## {#runjs}
<?php $jsCode = 'alert("Hello Jose");'; $client->runCode($jsCode);## Run javascript when the application is ready ## {#runwhenready}
<?php $jsCode = 'alert("Hello Jose");'; $client->ready($jsCode);