Overview

Packages

  • tipy

Classes

  • Tipy
  • TipyApp
  • TipyCli
  • TipyCliSession
  • TipyConfig
  • TipyController
  • TipyCookie
  • TipyDAO
  • TipyEnv
  • TipyFlash
  • TipyInflector
  • TipyInput
  • TipyIOWrapper
  • TipyLogger
  • TipyMailer
  • TipyModel
  • TipyOutput
  • TipyRequest
  • TipySession
  • TipyTestCase
  • TipyTestRunner
  • TipyView

Exceptions

  • AssertionFailedException
  • CompileErrorException
  • CompileWarningException
  • CoreErrorException
  • CoreWarningException
  • DeprecatedException
  • NoMethodException
  • NoticeException
  • ParseException
  • RecoverableErrorException
  • StrictException
  • TipyDaoException
  • TipyException
  • TipyModelException
  • TipyRollbackException
  • TipyValidationException
  • UserDeprecatedException
  • UserErrorException
  • UserNoticeException
  • UserWarningException
  • WarningException
  • Overview
  • Package
  • Class
  • Deprecated
  • Todo

Class TipyView

V in MVC. HTML template engine based on PHP output buffer and PHP itself

  • Templates are located in app/views directory
  • Templates are simple php files with .php extension.
  • Templates have variables defined in controller's TipyOutput instance and don't
    have access to application context except TipyView instance represented by $this (see note below)
// app/controllers/BlogController.php
class BlogController extends TipyController {
    public function article() {
        $this->out('title', 'Hello');
        $this->out('message', 'World!');
    }
}
// app/views/blog/article.php
<!DOCTYPE html>
<html>
<head>
    <title><?= $title ></title>
</head>
<body>
    <p><?= $title.' '.$message ?></p>
</body>
</html>

Custom template names

You can explicitely render views with custom names

// app/controllers/BlogController.php
class BlogController extends TipyController {
    public function article() {
        $this->out('title', 'Hello');
        $this->out('message', 'World!');
        $this->renderView('path/to/custom_template');
    }
}

Note about $this

$this is available inside template and gives access to TipyView instance which renders current template.

<ul>
    <li>
        <? $this->includeTemplate('item') ?>
    </li>
</ul>
Package: tipy
Located at src/TipyView.php
Methods summary
public
# __construct( )
public
# bind( array $map )

Assign variables map to template. This will replace all output data.

Assign variables map to template. This will replace all output data.

public mixed
# get( string $key, mixed $defaultValue,… )

Get value of the variable assigned to template by variable name. If $key does not exists may return $defaultValue.

Get value of the variable assigned to template by variable name. If $key does not exists may return $defaultValue.

Parameters

$key
$defaultValue,…

Returns

mixed
public
# set( string $key, mixed $value )

Assign variable to template

Assign variable to template

Parameters

$key
$value
public array
# getAll( )

Get all assigned variables

Get all assigned variables

Returns

array
public
# setTemplatePath( string $path )

Set path to templates

Set path to templates

Parameters

$path
public string
# processTemplate( string $templateName )

Compile template and return result as a string

Compile template and return result as a string

Parameters

$templateName

Returns

string
public string
# expandTemplatePath( string $templateName )

Get full path to template file

Get full path to template file

Parameters

$templateName

Returns

string
protected
# includeTemplate( string $templateName )

Include template (child) to currently rendering template (parent). All parent template variables will be available to its children as they exist in one context.

Include template (child) to currently rendering template (parent). All parent template variables will be available to its children as they exist in one context.

Should be called from template via $this.

<ul>
    <li>
        <? $this->includeTemplate('item') ?>
    </li>
</ul>

Parameters

$templateName
protected
# applyTemplateStart( string $templateName )

Wrap another template (layout) around currently rendering template or even its part (child).

Wrap another template (layout) around currently rendering template or even its part (child).

Layout template should have $this->childContent() call to specify where child template will be inserted.

All defined variables will be available in both templates as they exist in one context.

Should be called from template via $this

// app/views/child.php
<p>
<? $this->applyTemplateStart('layout') ?>
    TipyView is cool!
<? $this->applyTemplateEnd('layout') ?>
</p>
// app/views/layout.php
<strong>
    <? $this->childContent() ?>
</strong>

Will be rendered as

<p>
<strong>
    TipyView is cool!
</strong>
</p>

Parameters

$templateName
protected
# applyTemplateEnd( )

Indicates the end of layout

Indicates the end of layout

See

TipyView::applyTemplateStart()
protected
# childContent( )

Insert caller template's content into layout template

Insert caller template's content into layout template

See

TipyView::applyTemplateStart()
tipy API documentation generated by ApiGen