# Creating New Action

pro business

# Example

  1. Create new file in /var/www/keitaro/application/redirects/. For example, /var/www/keitaro/application/redirects/jsonp.php.

  2. The boilerplate code:

<?php
namespace Redirects;

use Traffic\Actions\AbstractAction;

class jsonp extends AbstractAction
{
    protected $_name = 'JSONP';     // <-- Action name
    protected $_weight = 100;            // <-- Action weight in action dropdown

    public function getType()
    {
        return self::TYPE_OTHER;              // <-- That tells Keitaro that script is an action 
    }

    protected function _execute()  
    {
        $url = $this->getActionPayload();
        
        $json = json_encode(['url' => $url]);
    
        $this->setContentType('application/javascript')  // <-- Set content type 
        $this->setStatus(200);                           // <-- Set 200 as HTTP status code
        $this->setContent($json);                        // <-- Sets $json as output 
    }
}
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

# 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"