Class AkActionView

(line 92)

Description

AkObject
   |
   --AkActionView

Located in File: /AkActionView.php

Action View templates can be written in two ways. If the template file has a +.tpl+ extension then it uses PHP.

= PHP

You trigger PHP by using embeddings such as <? ?>, <?php ?> and <?= ?>. The difference is whether you want output or not. Consider the following loop for names:

Names of all the people <?php foreach($people as $person) : ?> Name: <?=$person->name ?>
<?php endforeach ?>

== Using sub templates

Using sub templates allows you to sidestep tedious replication and extract common display structures in shared templates. The classic example is the use of a header and footer (even though the Action Pack-way would be to use Layouts):

<?= $controller->render("shared/header") ?> Something really specific and terrific <?= $controller->render("shared/footer") ?>

As you see, we use the output embeddings for the render methods. The render call itself will just return a string holding the result of the rendering. The output embedding writes it to the current template.

But you don't have to restrict yourself to static includes. Templates can share variables amongst themselves by using instance variables defined using the regular embedding tags. Like this:

<?php $shared->page_title = "A Wonderful Hello" ?> <?= $controller->render("shared/header") ?>

Now the header can pick up on the $page_title variable and use it for outputting a title tag:

<title><?= $page_title ?></title>

== Passing local variables to sub templates

You can pass local variables to sub templates by using an array with the variable names as keys and the objects as values:

<?= $controller->render("shared/header", array('headline'=>'Welcome','person'=> $person )) ?>

These can now be accessed in shared/header with:

Headline: <?= $headline ?> First name: <?= $person->first_name ?>

== JavaScriptGenerator ==



Class Variables

Summary:
mixed $assigns
mixed $base_path
mixed $controller
mixed $flash
mixed $headers
mixed $logger
mixed $params
mixed $request
mixed $response
mixed $session

$assigns (line 94)

Data type : mixed

$base_path (line 94)

Data type : mixed

$controller (line 94)

Data type : mixed

$first_render (line 94)

Data type : mixed

$flash (line 95)

Data type : mixed

$headers (line 95)

Data type : mixed

$logger (line 95)

Data type : mixed

$params (line 95)

Data type : mixed

$request (line 95)

Data type : mixed

$response (line 95)

Data type : mixed

$session (line 95)

Data type : mixed

$template_args = array() (line 97)

Data type : mixed

$template_extension (line 94)

Data type : mixed

$_template_handlers = array() (line 96)

Data type : mixed

Class Constants

Summary:

Method Detail

Summary:
static void _addGlobalVar ( $var_name,  $value, [ $_retrieve = false])
static void _getGlobals ()
AkActionView AkActionView ([ $base_path = null], [ $assigns_for_first_render = array()], [ $controller = null])
void addSharedAttributes ( &$local_assigns)
void delegateTemplateExists ( $template_path)
void evaluateAssigns ()
void fileIsPublic ( $template_path)
void getFullTemplatePath ( $template_path,  $extension)
void pickTemplateExtension ( $template_path)
void render ([ $options = array()])
void renderCollectionOfPartials ( $partial_name,  $collection, [ $partial_spacer_template = null], [ $local_assigns = array()])
void renderFile ( $template_path, [ $use_full_path = true], [ $local_assigns = array()])
void renderPartial ( $partial_path,  $object, [ $local_assigns = array()])
void renderPartialCollection ( $partial_name,  $collection, [ $partial_spacer_template = null], [ $local_assigns = array()])
void renderTemplate ( $____template_extension,  $____template, [ $____file_path = null], [ $____local_assigns = array()], [ $____save_content_in_attribute_as = 'layout'])
void _addObjectToLocalAssigns ( $partial_name,  $local_assigns,  &$object)
void _addObjectToLocalAssigns_ ( $partial_name,  &$local_assigns,  $object)
void _delegateRender ( $handler,  $template,  $local_assigns,  $file_path)
void &_extractingObject ( $partial_name,  &$deprecated_local_assigns)
void _javascriptTemplateExists ( $template_path)
void _loadHelpers ([ $helper_dir = null])
void _partialCounterName ( $partial_name)
void _partialPathName ( $partial_path)
void _partialPathPiece ( $partial_path)
void _readTemplateFile ( $template_path)
void _registerTemplateHandler ( $extension,  $className)
void _templateExists ( $template_path,  $extension)

Static Method _addGlobalVar (line 447)

void _addGlobalVar( $var_name, $value, [ $_retrieve = false])

Variables assigned using this method will act on any controller or action. Use this in conjunction with your application helpers in order to allow variable passing from inside your views.

This is used for example on the capture helper.

Parameters

  • $var_name:
  • $value:
  • $_retrieve:

Info

Static Method _getGlobals (line 460)

void _getGlobals( )

Info

Constructor AkActionView (line 135)

AkActionView AkActionView( [ $base_path = null], [ $assigns_for_first_render = array()], [ $controller = null])

Parameters

  • $base_path:
  • $assigns_for_first_render:
  • $controller:

Info

Method addSharedAttributes (line 216)

void addSharedAttributes( &$local_assigns)

Parameters

  • &$local_assigns:

Info

Method delegateTemplateExists (line 235)

void delegateTemplateExists( $template_path)

Parameters

  • $template_path:

Info

Method evaluateAssigns (line 274)

void evaluateAssigns( )

Info

Method fileIsPublic (line 248)

void fileIsPublic( $template_path)

Returns true is the file may be rendered implicitly.

Parameters

  • $template_path:

Info

Method getFullTemplatePath (line 253)

void getFullTemplatePath( $template_path, $extension)

Parameters

  • $template_path:
  • $extension:

Info

Method pickTemplateExtension (line 221)

void pickTemplateExtension( $template_path)

Parameters

  • $template_path:

Info

Method render (line 171)

void render( [ $options = array()])

Renders the template present at <tt>template_path</tt> (relative to the template_root).

The array in <tt>local_assigns</tt> is made available as local variables.

Parameters

  • $options:

Info

Method renderCollectionOfPartials (line 386)

void renderCollectionOfPartials( $partial_name, $collection, [ $partial_spacer_template = null], [ $local_assigns = array()])

Parameters

  • $partial_name:
  • $collection:
  • $partial_spacer_template:
  • $local_assigns:

Info

Method renderFile (line 149)

void renderFile( $template_path, [ $use_full_path = true], [ $local_assigns = array()])

Renders the template present at <tt>template_path</tt>. If <tt>use_full_path</tt> is set to true, it's relative to the template_root, otherwise it's absolute. The array in <tt>local_assigns</tt> is made available as local variables.

Parameters

  • $template_path:
  • $use_full_path:
  • $local_assigns:

Info

Method renderPartial (line 346)

void renderPartial( $partial_path, $object, [ $local_assigns = array()])

Partial Views

There's also a convenience method for rendering sub templates within the current controller that depends on a single object (we call this kind of sub templates for partials). It relies on the fact that partials should follow the naming convention of being prefixed with an underscore -- as to separate them from regular templates that could be rendered on their own.

In a template for AdvertiserController::account:

<?= $controller->render(array('partial' => 'account')); ?>

This would render "advertiser/_account.tpl" and pass the instance variable $controller->account in as a local variable $account to the template for display.

In another template for Advertiser::buy, we could have:

<?= $controller->render(array('partial' =>'account','locals'=>array('account'=>$buyer))); ?>

<?php foreach($advertisements as $ad) : ?> <?= $controller->render(array('partial'=>'ad','locals'=>array('ad'=>$ad))); ?> <?php endforeach; ?>

This would first render "advertiser/_account.tpl" with $buyer passed in as the local variable $account, then render "advertiser/_ad.tpl" and pass the local variable $ad to the template for display.

== Rendering a collection of partials

The example of partial use describes a familiar pattern where a template needs to iterate over an array and render a sub template for each of the elements. This pattern has been implemented as a single method that accepts an array and renders a partial by the same name as the elements contained within. So the three-lined example in "Using partials" can be rewritten with a single line:

<?= $controller->render(array('partial'=>'ad','collection'=>(array)$advertisements)); ?>

This will render "advertiser/_ad.tpl" and pass the local variable +ad+ to the template for display. An iteration counter will automatically be made available to the template with a name of the form +partial_name_counter+. In the case of the example above, the template would be fed +ad_counter+.

== Rendering shared partials

Two controllers can share a set of partials and render them like this:

<?= $controller->render(array('partial'=>'advertiser/ad', 'locals' => array('ad' => $advertisement ))); ?>

This will render the partial "advertiser/_ad.tpl" regardless of which controller this is being called from.

Parameters

  • $partial_path:
  • $object:
  • $local_assigns:

Info

Method renderPartialCollection (line 357)

void renderPartialCollection( $partial_name, $collection, [ $partial_spacer_template = null], [ $local_assigns = array()])

Parameters

  • $partial_name:
  • $collection:
  • $partial_spacer_template:
  • $local_assigns:

Info

Method renderTemplate (line 195)

void renderTemplate( $____template_extension, $____template, [ $____file_path = null], [ $____local_assigns = array()], [ $____save_content_in_attribute_as = 'layout'])

Parameters

  • $____template_extension:
  • $____template:
  • $____file_path:
  • $____local_assigns:
  • $____save_content_in_attribute_as:

Info

Method _addObjectToLocalAssigns (line 425)

void _addObjectToLocalAssigns( $partial_name, $local_assigns, &$object)

Parameters

  • $partial_name:
  • $local_assigns:
  • &$object:

Info

Method _addObjectToLocalAssigns_ (line 430)

void _addObjectToLocalAssigns_( $partial_name, &$local_assigns, $object)

Parameters

  • $partial_name:
  • &$local_assigns:
  • $object:

Info

Method _assignVariablesFromController (line 288)

void _assignVariablesFromController( )

Info

Method _delegateRender (line 282)

void _delegateRender( $handler, $template, $local_assigns, $file_path)

Parameters

  • $handler:
  • $template:
  • $local_assigns:
  • $file_path:

Info

Method _extractingObject (line 416)

void &_extractingObject( $partial_name, &$deprecated_local_assigns)

Parameters

  • $partial_name:
  • &$deprecated_local_assigns:

Info

Method _javascriptTemplateExists (line 295)

void _javascriptTemplateExists( $template_path)

Parameters

  • $template_path:

Info

Method _loadHelpers (line 101)

void _loadHelpers( [ $helper_dir = null])

Parameters

  • $helper_dir:

Info

Method _partialCounterName (line 411)

void _partialCounterName( $partial_name)

Parameters

  • $partial_name:

Info

Method _partialPathName (line 406)

void _partialPathName( $partial_path)

Parameters

  • $partial_path:

Info

Method _partialPathPiece (line 392)

void _partialPathPiece( $partial_path)

Parameters

  • $partial_path:

Info

Method _readTemplateFile (line 269)

void _readTemplateFile( $template_path)

This method reads a template file.

Parameters

  • $template_path:

Info

Method _registerTemplateHandler (line 130)

void _registerTemplateHandler( $extension, $className)

Register a class that knows how to handle template files with the given extension. This can be used to implement new template types.

The constructor for the class must take the AkActionView instance as a parameter, and the class must implement a "render" method that takes the contents of the template to render as well as the array of local assigns available to the template. The "render" method ought to return the rendered template as a string.

Parameters

  • $extension:
  • $className:

Info

Method _templateExists (line 259)

void _templateExists( $template_path, $extension)

Parameters

  • $template_path:
  • $extension:

Info

Inherited Variables

Inherited Class Variable Summary

Inherited Methods

Inherited Method Summary

Inherited From Class AkObject

AkObject::AkObject() - A hack to support __construct() on PHP 4

AkObject::__construct() - Class constructor, overriden in descendant classes

AkObject::freeMemory() - Unsets circular reference children that are not freed from memory when calling unset() or when the parent object is garbage collected.

AkObject::log() -

AkObject::toString() - Object-to-string conversion

AkObject::__clone() - Clone class (Zend Engine 2 compatibility trick)

AkObject::__destruct() - Class destructor, overriden in descendant classes

AkObject::__toString() -



Documentation generated on Tue, 17 Jun 2008 14:23:13 +0200 by phpDocumentor 1.3.2