Class \Scrivo\LayoutAction

The layout class provides a template system.

By unsing this layout class you can break down a larger template into smaller and manageble sections. These sections are named an can be used in other sections.

Consider the following data:

$data = new \stdClass;
$data->content = "Scrivo hello";
$data->menu = array("News", "Events", "Contact");

To display this data we first create a master template "master.tpl.php":

<html lang="en_EN">
  <body>
    <div class="menu">
      <?php echo $this->getSection("menu"); ?>
    </div>
    <div class="content">
      <?php echo $this->getSection("content"); ?>
    </div>
  </body>
</html>

And another template file "sections.tpl.php" in which we define the sections:

<?php
$this->beginSection("menu", true);
?>
    <ul>
    <?php foreach ($data->menu as $m) { ?>
        <li><?php echo $m?></li>
    <?php } ?>
    </ul>
?>
$this->endSection();

$this->beginSection("content");
?>
    <p><?php echo $data->content?></p>
<?php
$this->endSection("content", true);
?>

Now we can apply the templates on the data using the following:

class MyLayout extends Layout {
    function apply($data) {
        include "sections.tpl.php";
        $this->useLayout("master.tpl.php");
        include $this->getLayout();
    }
}
$l = new MyLayout();
$l->apply($data);

Extends \Scrivo\Action .
Defined in: LayoutAction.php.


Constructor summary

Attr. Name / Description
public

LayoutAction(, , , )

Constant summary

Name Description
ACTION
AUTH
DOWNLOAD
FAIL
FILE
FORWARD
PARAMS
SUCCESS
TYPE
VIEW
WARN
XHR

Member summary

Attr. Type Name Description
private $action
private $auth
protected $context
private $file
private $forward
private array $layout The layout used for rendering.
protected $parameters
private $result
private $resultData
private array $sections An array containing the all the sections defined.
protected $session
private array $stored Stack of section options.
private $type

Method summary

Attr. Type Name / Description
public mixed

__get($name)

Implementation of the readable properties using the PHP magic method __get().

public

beginSection($name, $overwrite)

Mark the beginning of a layout section.

public static

create(, , , )

public

endSection()

Mark the end of a layout section.

public

forward()

public array

getAllSections()

Retrieves all sections.

public string

getLayout()

Gets the currently defined layout to use for rendering.

public string

getSection($name)

Retrieve the content of section with the provided name.

public

getView()

public

getXhr()

public

prepareXhr()

public

renderSection($name, $function, $parameters)

Uses a function to render the content of a section.

private array

sectionOptions($name, $overwrite)

Gets or sets options for defining a section.

public

setParameters()

public

setResult(, , )

public string

setSection($name, $content, $overwrite)

Assigns provided content to a specific section.

public string

useLayout($layout)

Define the layout to use for rendering.

 


Constructor

public LayoutAction(, , , =null)

Inherited from \Scrivo\Action

Parameters:

Type Name Def. Description
$context $context
$action $action
$userStatus $userStatus
$session $session null

Constants

ACTION

Inherited from \Scrivo\Action

Value: 10

AUTH

Inherited from \Scrivo\Action

Value: 8

DOWNLOAD

Inherited from \Scrivo\Action

Value: 11

FAIL

Inherited from \Scrivo\Action

Value: 6

FILE

Inherited from \Scrivo\Action

Value: 4

FORWARD

Inherited from \Scrivo\Action

Value: 2

PARAMS

Inherited from \Scrivo\Action

Value: 9

SUCCESS

Inherited from \Scrivo\Action

Value: 5

TYPE

Inherited from \Scrivo\Action

Value: 3

VIEW

Inherited from \Scrivo\Action

Value: 1

WARN

Inherited from \Scrivo\Action

Value: 7

XHR

Inherited from \Scrivo\Action

Value: 12


Members


				
private $action

Inherited from \Scrivo\Action

Inital value: null


				
private $auth

Inherited from \Scrivo\Action

Inital value: \Scrivo\User::STATUS_MEMBER


				
protected $context

Inherited from \Scrivo\Action

Inital value: null


				
private $file

Inherited from \Scrivo\Action

Inital value: null


				
private $forward

Inherited from \Scrivo\Action

Inital value: array()


				
private array $layout

The layout used for rendering.

Inital value: ""


				
protected $parameters

Inherited from \Scrivo\Action

Inital value: null


				
private $result

Inherited from \Scrivo\Action

Inital value: self::FAIL


				
private $resultData

Inherited from \Scrivo\Action

Inital value: null


				
private array $sections

An array containing the all the sections defined.

Inital value: array()


				
protected $session

Inherited from \Scrivo\Action

Inital value: null


				
private array $stored

Stack of section options.

Inital value: array()


				
private $type

Inherited from \Scrivo\Action

Inital value: null


Methods

public mixed __get(string $name)

Implementation of the readable properties using the PHP magic method __get().

Inherited from \Scrivo\Action

Parameters:

Type Name Def. Description
string $name

The name of the property to get.

Returns:

mixed Implementation of the readable properties using the PHP magic method __get().

public beginSection(string $name, boolean $overwrite=false)

Mark the beginning of a layout section.

Buffers all output until the end of the section is marked.

Parameters:

Type Name Def. Description
string $name

The name of the section (currently only present for readability of the code where used).

boolean $overwrite false

Overwrite previous content if existing? Default will append it to existing.

public static create(, , , )

Inherited from \Scrivo\Action

Parameters:

Type Name Def. Description
$context $context
$action $action
$userStatus $userStatus
$session $session
public endSection()

Mark the end of a layout section.

Assigns all buffered output to the section with the provided name.

public forward()

Inherited from \Scrivo\Action

public array getAllSections()

Retrieves all sections.

Returns:

array Retrieves all sections.

public string getLayout()

Gets the currently defined layout to use for rendering.

Returns:

string Gets the currently defined layout to use for rendering.

public string getSection(string $name)

Retrieve the content of section with the provided name.

Parameters:

Type Name Def. Description
string $name

The name of the section to get the content of.

Returns:

string Retrieve the content of section with the provided name.

public getView()

Inherited from \Scrivo\Action

public getXhr()

Inherited from \Scrivo\Action

public prepareXhr()

Inherited from \Scrivo\Action

Parameters:

Type Name Def. Description
$data $data
public renderSection(string $name, callable $function, array $parameters=array())

Uses a function to render the content of a section.

Parameters:

Type Name Def. Description
string $name

The name of the section to render the content of.

callable $function

The function which renders the content.

array $parameters array()

Optional array of parameters which will be passed to the function.

private array sectionOptions(null $name=null, null $overwrite=null)

Gets or sets options for defining a section.

Parameters:

Type Name Def. Description
null $name null
null $overwrite null

Returns:

array Gets or sets options for defining a section.

public setParameters()

Inherited from \Scrivo\Action

Parameters:

Type Name Def. Description
$arr $arr
public setResult(, =null, =null=null)

Inherited from \Scrivo\Action

Parameters:

Type Name Def. Description
$res $res
$result $result null
$form_data $form_data null
public string setSection(string $name, string $content=null, boolean $overwrite=false)

Assigns provided content to a specific section.

If no content is provided the stored content of the section will be returned.

Parameters:

Type Name Def. Description
string $name

The section to set the content of.

string $content null

The content to assign to the section.

boolean $overwrite false

Overwrite previous content if existing? Default will append it to existing.

Returns:

string Assigns provided content to a specific section.

public string useLayout(string $layout=null)

Define the layout to use for rendering.

If no layout is provided the previously defined layout will be returned.

Parameters:

Type Name Def. Description
string $layout null

The layout to use.

Returns:

string Define the layout to use for rendering.


Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013