# Custom action
# Example
Create new file in
/var/www/keitaro/var/redirects/. For example,/var/www/keitaro/var/redirects/jsonp.php.The boilerplate code:
<?php
namespace Redirects;
use Traffic\Actions\AbstractAction;
class TestAction extends AbstractAction
{
protected $_name = 'Test Action'; // <-- Action name
protected $_weight = 100; // <-- Weight for sorting in the actions list
public function getField(): string
{
return self::NOTHING;
}
public function getType()
{
return self::TYPE_OTHER; // <-- Defines the type
}
protected function _execute()
{
$this->setContentType('application/json'); // <-- Sets content type
$this->setStatus(200); // <-- Sets 200 as HTTP response
$this->setContent(json_encode([ // <-- Sets json as response body
'success' => true
]));
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Available methods
These methods available inside _execute():
| Method | Type | Description |
|---|---|---|
$this->getRawClick() | RawClick | Get instance of RawClick |
$this->getStream() | Flow | Get an instance of Flow |
$this->getCampaign() | Campaign | Get an instance of Campaign |
$this->getLanding() | Landing | Get an instance of Landing Page |
$this->getOffer() | Offer | Get an instance of Offer |
$this->getServerRequest() | ServerRequest | PSR-7 ServerRequest |
$this->getActionPayload() | mixed | Get action payload after placeholders applied |
$this->getRawActionPayload() | mixed | Get action payload before placeholders applied |
$this->getActionOptions() | mixed | Get action options |
$this->addHeader($string) | void | Add header sting to the response |
$this->redirect($string) | void | Do the same as $this->addHeader('Location: ...') |
$this->setContent($string) | void | Set output |
$this->setContentType($string) | void | Set content type (for example, application/javascript) |
$this->setStatus($number) | void | Set HTTP header status (for example, 302) |
$this->setDestinationInfo($string) | void | Set value for "Destination" |