Documentation

Controller extends CI_Controller
in package

AbstractYes

CI_Controller extension.

Table of Contents

Properties

$httpResponse  : HttpResponse
HttpResponse instance.
$library  : string|array<string|int, string>
Auto-loading library name.
$model  : string|array<string|int, string>
Auto-loading model name.

Methods

__construct()  : mixed
Initialize the controller.
internalRedirect()  : void
Internal redirect.
beforeDownload()  : mixed
Called just before downloading. Override as needed.
beforeInternalRedirect()  : mixed
Called just before the internal redirect. Override as needed.
beforeResponse()  : mixed
Called just before response. Override as needed.
beforeResponseHtml()  : mixed
Called just before the HTML response. Override as needed.
beforeResponseImage()  : mixed
Called just before the image response. Override as needed.
beforeResponseJs()  : mixed
Called just before the JS response. Override as needed.
beforeResponseJson()  : mixed
Called just before the JSON response. Override as needed.
beforeResponseText()  : mixed
Called just before plain text response. Override as needed.
beforeResponseView()  : mixed
Called just before the template response. Override as needed.
clear()  : Controller
Clear response.
download()  : void
Download file.
error()  : void
Error response.
html()  : void
Response HTML.
image()  : void
Response image.
js()  : void
Response js.
json()  : void
Response JSON.
set()  : Controller
Set response.
setCorsHeader()  : Controller
Sets the CORS header.
status()  : Controller
Set HTTP status.
text()  : void
Response Plain text.
view()  : void
Responds with the result of compiling the specified template into HTML.
getReferer()  : string
Get referrer.

Properties

$library

Auto-loading library name.

protected string|array<string|int, string> $library

$model

Auto-loading model name.

protected string|array<string|int, string> $model

Methods

__construct()

Initialize the controller.

public __construct() : mixed

internalRedirect()

Internal redirect.

public internalRedirect(string $redirectPath) : void

Allows for internal redirection to a location determined by a header returned from a backend. This allows the backend to authenticate and perform any other processing, provide content to the end user from the internally redirected location, and free up the backend to handle other requests.

Nginx:

# Will serve /var/www/files/myfile
# When passed URI /protected/myfile
location /protected {
  internal;
  alias /var/www/files;
}
``

PHP:
```php
class Sample extends \X\Controller\Controller {
  public function index() {
    parent::internalRedirect('/protected/myfile');
  }
}
Parameters
$redirectPath : string

Path to internal redirect.

beforeDownload()

Called just before downloading. Override as needed.

protected beforeDownload(string $referer) : mixed
Parameters
$referer : string

Referrer.

beforeInternalRedirect()

Called just before the internal redirect. Override as needed.

protected beforeInternalRedirect(string $referer) : mixed
Parameters
$referer : string

Referrer.

beforeResponse()

Called just before response. Override as needed.

protected beforeResponse(string $referer) : mixed
Parameters
$referer : string

Referrer.

beforeResponseHtml()

Called just before the HTML response. Override as needed.

protected beforeResponseHtml(string $referer) : mixed
Parameters
$referer : string

Referrer.

beforeResponseImage()

Called just before the image response. Override as needed.

protected beforeResponseImage(string $referer) : mixed
Parameters
$referer : string

Referrer.

beforeResponseJs()

Called just before the JS response. Override as needed.

protected beforeResponseJs(string $referer) : mixed
Parameters
$referer : string

Referrer.

beforeResponseJson()

Called just before the JSON response. Override as needed.

protected beforeResponseJson(string $referer) : mixed
Parameters
$referer : string

Referrer.

beforeResponseText()

Called just before plain text response. Override as needed.

protected beforeResponseText(string $referer) : mixed
Parameters
$referer : string

Referrer.

beforeResponseView()

Called just before the template response. Override as needed.

protected beforeResponseView(string $referer) : mixed
Parameters
$referer : string

Referrer.

download()

Download file.

protected download(string $filename[, string $content = '' ][, bool $mime = false ]) : void
Parameters
$filename : string

Download file name.

$content : string = ''

(optional) Downloadable Content.

$mime : bool = false

(optional) MIME Type. The default is false and the MIME type is automatically detected.

error()

Error response.

protected error(string $message[, int $httpStatus = 500 ][, bool $forceJsonResponse = false ]) : void
Parameters
$message : string

Error message.

$httpStatus : int = 500

(optional) HTTP status.

$forceJsonResponse : bool = false

(optional) Force a response with Content-Type "application/json".

html()

Response HTML.

protected html(string $html) : void
Parameters
$html : string

HTML string.

image()

Response image.

protected image(string $imagePath) : void
Parameters
$imagePath : string

Image path.

js()

Response js.

protected js(string $js) : void
Parameters
$js : string

JS Code.

json()

Response JSON.

protected json([bool $forceObject = false ][, bool $prettyrint = false ]) : void
Parameters
$forceObject : bool = false

(optional) Outputs an object rather than an array when a non-associative array is used.

$prettyrint : bool = false

(optional) Use whitespace in returned data to format it.

set()

Set response.

protected set(mixed $key[, mixed|null $value = null ]) : Controller
Parameters
$key : mixed

If one argument, the response data. If two arguments, the field name of the response data.

$value : mixed|null = null

Response data.

Return values
Controller

setCorsHeader()

Sets the CORS header.

protected setCorsHeader([string $origin = '*' ]) : Controller
// Allow all.
parent::setCorsHeader('*');

// Only any origin is allowed.
parent::setCorsHeader('http://www.example.jp');
parent::setCorsHeader('http://www.example.jp https://www.example.jp http://sub.example.jp');

// To set the same Access-Control-Allow-Origin for all responses, use the hook point called before the response.
abstract class AppController extends \X\Controller\Controller {
  protected function beforeResponse(string $referer) {
    $this->setCorsHeader('*');
  }
}
Parameters
$origin : string = '*'

Allowable Origins.

Return values
Controller

text()

Response Plain text.

protected text(string $plainText) : void
Parameters
$plainText : string

Plain text.

view()

Responds with the result of compiling the specified template into HTML.

protected view(string $templatePath) : void
Parameters
$templatePath : string

Template path.

getReferer()

Get referrer.

private getReferer() : string
Return values
string

Referrer.


        
On this page

Search results