PHP 클래스 CsvView\View\CsvView

By setting the '_serialize' key in your controller, you can specify a view variable that should be serialized to CSV and used as the response for the request. This allows you to omit views + layouts, if your just need to emit a single view variable as the CSV response. In your controller, you could do the following: $this->set(['posts' => $posts, '_serialize' => 'posts']); When the view is rendered, the $posts view variable will be serialized into CSV. When rendering the data, the data should be a single, flat array. If this is not the case, then you should also specify an _extract variable: $_extract = [ ['id', '%d'], // Hash-compatible path, sprintf-compatible format 'description', // Hash-compatible path function ($row) { // Callable return value } ]; You can also define '_serialize' as an array. This will create a top level object containing all the named view variables: $this->set(compact('posts', 'users', 'stuff')); $this->set('_serialize', array('posts', 'users')); Each of the viewVars in _serialize would then be output into the csv If you don't use the _serialize key, you will need a view. You can use extended views to provide layout like functionality. When not using custom views, you may specify the following view variables: - array $_header: (default null) A flat array of header column names - array $_footer: (default null) A flat array of footer column names - string $_delimiter: (default ',') CSV Delimiter, defaults to comma - string $_enclosure: (default '"') CSV Enclosure for use with fputscsv() - string $_eol: (default '\n') End-of-line character the csv
상속: extends Cake\View\View
파일 보기 프로젝트 열기: friendsofcake/cakephp-csvview

공개 프로퍼티들

프로퍼티 타입 설명
$layoutPath string CSV layouts are located in the csv sub directory of Layouts/
$subDir string CSV views are always located in the 'csv' sub directory for a controllers views.

보호된 프로퍼티들

프로퍼티 타입 설명
$_resetStaticVariables boolean Whether or not to reset static variables in use
$_specialVars array List of special view vars.

공개 메소드들

메소드 설명
__construct ( Cake\Network\Request $request = null, Response $response = null, Cake\Event\EventManager $eventManager = null, array $viewOptions = [] ) Constructor
loadHelpers ( ) : void Skip loading helpers if this is a _serialize based view.
render ( string | null $view = null, string | null $layout = null ) : string Render a CSV view.

보호된 메소드들

메소드 설명
_generateRow ( array | null $row = null ) : string | false Generates a single row in a csv from an array of data by writing the array to a temporary file and returning it's contents
_renderContent ( ) : void Renders the body of the data to the csv
_renderRow ( array | null $row = null ) : null | string Aggregates the rows into a single csv
_serialize ( ) : string Serialize view vars.
_setupViewVars ( ) : void Setup defaults for CsvView view variables

메소드 상세

__construct() 공개 메소드

Constructor
public __construct ( Cake\Network\Request $request = null, Response $response = null, Cake\Event\EventManager $eventManager = null, array $viewOptions = [] )
$request Cake\Network\Request Request instance.
$response Cake\Network\Response Response instance.
$eventManager Cake\Event\EventManager EventManager instance.
$viewOptions array An array of view options

_generateRow() 보호된 메소드

Generates a single row in a csv from an array of data by writing the array to a temporary file and returning it's contents
protected _generateRow ( array | null $row = null ) : string | false
$row array | null Row data
리턴 string | false String with the row in csv-syntax, false on fputscv failure

_renderContent() 보호된 메소드

Renders the body of the data to the csv
protected _renderContent ( ) : void
리턴 void

_renderRow() 보호된 메소드

Aggregates the rows into a single csv
protected _renderRow ( array | null $row = null ) : null | string
$row array | null Row data
리턴 null | string CSV with all data to date

_serialize() 보호된 메소드

Serialize view vars.
protected _serialize ( ) : string
리턴 string The serialized data

_setupViewVars() 보호된 메소드

The following variables can be retrieved from '$this->viewVars' for use in configuring this view: - array '_header': (default null) A flat array of header column names - array '_footer': (default null) A flat array of footer column names - array '_extract': (default null) An array of Hash-compatible paths or callable with matching 'sprintf' $format as follows: $_extract = [ [$path, $format], [$path], $path, function () { ... } // Callable ]; If a string or unspecified, the format default is '%s'. - '_delimiter': (default ',') CSV Delimiter, defaults to comma - '_enclosure': (default '"') CSV Enclosure for use with fputscsv() - '_newline': (default '\n') CSV Newline replacement for use with fputscsv() - '_eol': (default '\n') End-of-line character the csv - '_bom': (default false) Adds BOM (byte order mark) header - '_setSeparator: (default false) Adds sep=[_delimiter] in the first line
protected _setupViewVars ( ) : void
리턴 void

loadHelpers() 공개 메소드

Skip loading helpers if this is a _serialize based view.
public loadHelpers ( ) : void
리턴 void

render() 공개 메소드

Uses the special '_serialize' parameter to convert a set of view variables into a CSV response. Makes generating simple CSV responses very easy. If you omit the '_serialize' parameter, and use a normal view + layout as well. Also has support for specifying headers and footers in '_header' and '_footer' variables, respectively.
public render ( string | null $view = null, string | null $layout = null ) : string
$view string | null The view being rendered.
$layout string | null The layout being rendered.
리턴 string The rendered view.

프로퍼티 상세

$_resetStaticVariables 보호되어 있는 프로퍼티

Whether or not to reset static variables in use
protected bool $_resetStaticVariables
리턴 boolean

$_specialVars 보호되어 있는 프로퍼티

List of special view vars.
protected array $_specialVars
리턴 array

$layoutPath 공개적으로 프로퍼티

CSV layouts are located in the csv sub directory of Layouts/
public string $layoutPath
리턴 string

$subDir 공개적으로 프로퍼티

CSV views are always located in the 'csv' sub directory for a controllers views.
public string $subDir
리턴 string