From 974e9db6c141d1b04d50d5df35d1c1ef311204cd Mon Sep 17 00:00:00 2001 From: Foxtrot Date: Sun, 8 May 2016 22:12:56 +0100 Subject: [PATCH] Add PHP info. --- creating_modules.md | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/creating_modules.md b/creating_modules.md index 85c1e84..37cb1a9 100644 --- a/creating_modules.md +++ b/creating_modules.md @@ -106,3 +106,52 @@ registerController("ExampleController", ['$api', '$scope', function($api, $scope This will send a request to our module.php, and take its response and set `$scope.text` to `response.text`. #### module.php +The module.php contains all PHP code and can directly interface with other modules, talk to the Javascript and access the WiFi Pineapple API. In this guide, we will finish our Example Module by making it reply to our AngularJS request and return a string containing "Hello World!". + +To start, we must extend the `Module` class inside of the `pineapple` namespace. We must then add the method to handle our requests.: +``` +request->action) { + case 'getHello': + $this->hello(); + break; + } + } +} +``` + +This snippet of code will loop over every action it receieves from the Javascript. In our case it is `getHello`. Once it finds `getHello` it will execute a function called `hello()` that we will define next. After the route() function: +``` +private function hello() +{ + $this->response = array('text' => "Hello World"); +} +``` + +Once this function is executed it will simply create an array with a property called text equaling "Hello World". All together, your code will look like this: +``` +request->action) { + case 'getHello': + $this->hello(); + break; + } + } + + private function hello() + { + $this->response = array('text' => "Hello World"); + } +} +``` +Our PHP is now complete, and when the HTML is loaded, it will now display the "Hello World" string from your module.php.