Amiro.CMS API Reference
Amiro.Ru / Manual
Loading search...

The AMI_Response class

• Introduction

CMS response.

• Class synopsis

AMI_Response {
/* Constants */
// Default status message code
const AMI_Response::STATUS_MESSAGE =  'none';
// 'Error' status message code
const AMI_Response::STATUS_MESSAGE_ERROR =  'error';
// 'Warning' status message code
const AMI_Response::STATUS_MESSAGE_WARNING =  'warn';
/* Methods */
// Add status message.
public addStatusMessage ( string $key, [ $aParams = array() ], [ string $type = self::STATUS_MESSAGE ], [ string $modId = '' ] ) returns AMI_Response;
// Enables bench info in response.
public displayBench ( ) returns AMI_Response;
// Returns JSON response.
public getJSONResponse ( mixed $content ) returns string;
// Returns true if response is already started.
public isStarted ( ) returns bool;
// Loads status message loacales.
public loadStatusMessages ( string $path, [ string $modId = '' ] ) returns AMI_Response;
// Delete all status messages.
public resetStatusMessages ( ) returns AMI_Response;
// Sends response and exits.
public send ( ) returns void;
// Sets page reload flag.
public setPageReload ( [ bool $needPageReload = TRUE ] ) returns AMI_HTTPResponse;
// Delay execution.
public sleep ( float $sleep ) returns AMI_Response;
// Starts reponse.
public start ( ) returns AMI_Resoponse;
// Writes data to the response.
public write ( mixed $data ) returns AMI_Resoponse;
}

• Class Details

Attention! Do not use response functionality in plugin CMS context code!
Plugin CMS context is always buffered and system is expecting plugin response in $resultHtml variable.

  Example:
  •  require 'ami_env.php';
  •  // @var AMI_Response
  •  $oResponse AMI::getSingleton('response');
  •  $oResponse->HTTP->setContentType('text/plain');
  •  $oResponse->HTTP->addHeader('Pragma: no-cache');
  •  $oResponse->HTML->addStyle('someStyles.css');
  •  $oResponse->HTML->addScript('someScript.js');
  •  $oResponse->start();
  •  $oResponse->write('Hello world');
  •  $oResponse->send();
Tags:
property-read AMI_HTTPResponse $HTTP: HTTP response part
property-read AMI_HTMLResponse $HTML: HTML response part
resource response AMI::getSingleton('response')

• Class Constants

STATUS_MESSAGE

Default status message code

STATUS_MESSAGE_ERROR

'Error' status message code

STATUS_MESSAGE_WARNING

'Warning' status message code

• Class Methods

// Add status message.
public addStatusMessage ( string $key, [ $aParams = array() ], [ string $type = self::STATUS_MESSAGE ], [ string $modId = '' ] ) returns AMI_Response;
  • string $key
    Status message key
  • array $aParams
    Message parameters
  • string $type
    Message type (STATUS_MESSAGE | STATUS_MESSAGE_WARNING | STATUS_MESSAGE_ERROR)
  • string $modId
    Module id
  Example:
  •  // AmiSample_ListActionsAdm.php {
  •  
  •  $aEvent['oResponse']->addStatusMessage(
  •      'status_copied',
  •      array(
  •          'source'      => $nickname,
  •          'destination' => $newNickname
  •      )
  •  );
  •  
  •  // } AmiSample_ListActionsAdm.php
// Enables bench info in response.
public displayBench ( ) returns AMI_Response;
// Returns JSON response.
public getJSONResponse ( mixed $content ) returns string;
  • mixed $content
    Data to convert to JSON
// Returns true if response is already started.
public isStarted ( ) returns bool;
Tags:
since 5.14.4
// Loads status message loacales.
public loadStatusMessages ( string $path, [ string $modId = '' ] ) returns AMI_Response;
  • string $path
    Locales path
  • string $modId
    Module id
  Example:
  •  // AmiSample_Adm.php::__construct()
  •  parent::__construct($oRequest$oResponse);
  •  $oResponse->loadStatusMessages('_local/plugins_distr/' $this->getModId('/templates/messages.lng');
Tags:
see AMI_Response::addStatusMessage()
since 5.12.4
// Delete all status messages.
public resetStatusMessages ( ) returns AMI_Response;
Tags:
see AMI_Response::addStatusMessage()
since 5.12.4
// Sends response and exits.
public send ( ) returns void;
Tags:
exitpoint
// Sets page reload flag.
public setPageReload ( [ bool $needPageReload = TRUE ] ) returns AMI_HTTPResponse;
  • bool $needPageReload
    Flag value
Tags:
since 5.14.4
// Delay execution.
public sleep ( float $sleep ) returns AMI_Response;
  • float $sleep
    Delay in microseconds
Metod is used for delay taking into benches.
// Starts reponse.
public start ( ) returns AMI_Resoponse;
// Writes data to the response.
public write ( mixed $data ) returns AMI_Resoponse;
  • mixed $data
    String for HTML response type or any data for JSON response type.