PHP Класс Piwik\View

View lets you set properties that will be passed on to a Twig template. View will also set several properties that will be available in all Twig templates, including: - **currentModule**: The value of the **module** query parameter. - **currentAction**: The value of the **action** query parameter. - **userLogin**: The current user login name. - **sites**: List of site data for every site the current user has at least view access for. - **url**: The current URL (sanitized). - **token_auth**: The current user's token auth. - **userHasSomeAdminAccess**: True if the user has admin access to at least one site, false if otherwise. - **userIsSuperUser**: True if the user is the superuser, false if otherwise. - **latest_version_available**: The latest version of Piwik available. - **isWidget**: The value of the 'widget' query parameter. - **show_autocompleter**: Whether the site selector should be shown or not. - **loginModule**: The name of the currently used authentication module. - **userAlias**: The alias of the current user. ### Template Naming Convention Template files should be named after the controller method they are used in. If they are used in more than one controller method or are included by another template, they should describe the output they generate and be prefixed with an underscore, eg, **_dataTable.twig**. ### Twig Twig templates must exist in the **templates** folder in a plugin's root folder. The following filters are available to twig templates: - **translate**: Outputs internationalized text using a translation token, eg, {{ 'General_Date'|translate }}. sprintf parameters can be passed to the filter. - **urlRewriteWithParameters**: Modifies the current query string with the given set of parameters, eg, {{ {'module':'MyPlugin', 'action':'index'} | urlRewriteWithParameters }} - **sumTime**: Pretty formats an number of seconds. - **money**: Formats a numerical value as a monetary value using the currency of the supplied site (second arg is site ID). eg, {{ 23|money(site.idsite)|raw }} - **truncate**: Truncates the text to certain length (determined by first arg.) eg, {{ myReallyLongText|truncate(80) }} - **implode**: Calls implode. - **ucwords**: Calls ucwords. The following functions are available to twig templates: - **linkTo**: Modifies the current query string with the given set of parameters, eg {{ linkTo({'module':'MyPlugin', 'action':'index'}) }}. - **sparkline**: Outputs a sparkline image HTML element using the sparkline image src link. eg, {{ sparkline(sparklineUrl) }}. - **postEvent**: Posts an event that allows event observers to add text to a string which is outputted in the template, eg, {{ postEvent('MyPlugin.event') }} - **isPluginLoaded**: Returns true if the supplied plugin is loaded, false if otherwise. {% if isPluginLoaded('Goals') %}...{% endif %}` ### Examples **Basic usage** a controller method public function myView() { $view = new View("@MyPlugin/myView"); $view->property1 = "a view property"; $view->property2 = "another view property"; return $view->render(); }
Наследование: implements Piwik\View\ViewInterface
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$templateVars

Открытые методы

Метод Описание
__construct ( string $templateFile ) Constructor.
__get ( string $key ) : mixed Retrieves an assigned variable.
__isset ( string $name ) : boolean Returns true if a template variable has been set or not.
__set ( string $key, mixed $val ) Directly assigns a variable to the view script.
addForm ( piwik\QuickForm2 $form ) Add form to view
assign ( string | array $var, mixed $value = null ) Assign value to a variable for use in a template
clearCompiledTemplates ( ) Clear compiled Twig templates
disableCacheBuster ( ) Disables the cache buster (adding of ?cb=.
getTemplateFile ( ) : string Returns the template filename.
getTemplateVars ( array $override = [] ) : array Returns the variables to bind to the template when rendering.
getTwig ( ) : Twig_Environment
render ( ) : string Renders the current view. Also sends the stored 'Content-Type' HTML header.
setContentType ( string $contentType ) Set stored value used in the Content-Type HTTP header field. The header is set just before rendering.
setXFrameOptions ( string $option = 'deny' ) Set X-Frame-Options field in the HTTP response. The header is set just before rendering.
singleReport ( string $title, string $reportHtml ) : string | void Creates a View for and then renders the single report template.

Защищенные методы

Метод Описание
applyFilter_cacheBuster ( $output )
renderTwigTemplate ( )

Приватные методы

Метод Описание
initializeTwig ( )

Описание методов

__construct() публичный Метод

Constructor.
public __construct ( string $templateFile )
$templateFile string The template file to load. Must be in the following format: `"@MyPlugin/templateFileName"`. Note the absence of .twig from the end of the name.

__get() публичный Метод

Variable names may not be prefixed with '_'.
public __get ( string $key ) : mixed
$key string The variable name.
Результат mixed The variable value.

__isset() публичный Метод

Returns true if a template variable has been set or not.
public __isset ( string $name ) : boolean
$name string The name of the template variable.
Результат boolean

__set() публичный Метод

Variable names may not be prefixed with '_'.
public __set ( string $key, mixed $val )
$key string The variable name.
$val mixed The variable value.

addForm() публичный Метод

Add form to view
public addForm ( piwik\QuickForm2 $form )
$form piwik\QuickForm2

applyFilter_cacheBuster() защищенный Метод

protected applyFilter_cacheBuster ( $output )

assign() публичный Метод

Assign value to a variable for use in a template
public assign ( string | array $var, mixed $value = null )
$var string | array
$value mixed

clearCompiledTemplates() публичный статический Метод

Clear compiled Twig templates
public static clearCompiledTemplates ( )

disableCacheBuster() публичный Метод

..) to JavaScript and stylesheet files
public disableCacheBuster ( )

getTemplateFile() публичный Метод

Returns the template filename.
public getTemplateFile ( ) : string
Результат string

getTemplateVars() публичный Метод

Returns the variables to bind to the template when rendering.
public getTemplateVars ( array $override = [] ) : array
$override array Template variable override values. Mainly useful when including View templates in other templates.
Результат array

getTwig() публичный Метод

public getTwig ( ) : Twig_Environment
Результат Twig_Environment

render() публичный Метод

See {@link setContentType()}.
public render ( ) : string
Результат string Generated template.

renderTwigTemplate() защищенный Метод

protected renderTwigTemplate ( )

setContentType() публичный Метод

Set stored value used in the Content-Type HTTP header field. The header is set just before rendering.
public setContentType ( string $contentType )
$contentType string

setXFrameOptions() публичный Метод

_Note: setting this allows you to make sure the View **cannot** be embedded in iframes. Learn more here._
public setXFrameOptions ( string $option = 'deny' )
$option string ('deny' or 'sameorigin')

singleReport() публичный статический Метод

Can be used for pages that display only one report to avoid having to create a new template.
public static singleReport ( string $title, string $reportHtml ) : string | void
$title string The report title.
$reportHtml string The report body HTML.
Результат string | void The report contents if `$fetch` is true.

Описание свойств

$templateVars защищенное свойство

protected $templateVars