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.
| Attr. | Name / Description |
|---|---|
| public |
LayoutAction(, , , ) |
| Name | Description |
|---|---|
| ACTION | |
| AUTH | |
| DOWNLOAD | |
| FAIL | |
| FILE | |
| FORWARD | |
| PARAMS | |
| SUCCESS | |
| TYPE | |
| VIEW | |
| WARN | |
| XHR |
| 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 |
| 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 |
Mark the end of a layout section. |
|
| public |
forward() |
|
| public | array |
Retrieves all sections. |
| public | string |
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 | ||
| 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 | ||
| 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 View source: Action.php line 74.
Constants
- ACTION
-
Inherited from \Scrivo\Action
Value: 10
View source: Action.php line 49.
- AUTH
-
Inherited from \Scrivo\Action
Value: 8
View source: Action.php line 47.
- DOWNLOAD
-
Inherited from \Scrivo\Action
Value: 11
View source: Action.php line 50.
- FAIL
-
Inherited from \Scrivo\Action
Value: 6
View source: Action.php line 45.
- FILE
-
Inherited from \Scrivo\Action
Value: 4
View source: Action.php line 43.
- FORWARD
-
Inherited from \Scrivo\Action
Value: 2
View source: Action.php line 41.
- PARAMS
-
Inherited from \Scrivo\Action
Value: 9
View source: Action.php line 48.
- SUCCESS
-
Inherited from \Scrivo\Action
Value: 5
View source: Action.php line 44.
- TYPE
-
Inherited from \Scrivo\Action
Value: 3
View source: Action.php line 42.
- VIEW
-
Inherited from \Scrivo\Action
Value: 1
View source: Action.php line 40.
- WARN
-
Inherited from \Scrivo\Action
Value: 7
View source: Action.php line 46.
- XHR
-
Inherited from \Scrivo\Action
Value: 12
View source: Action.php line 51.
Members
- private $action
-
Inherited from \Scrivo\Action
Inital value: null
View source: Action.php line 60.
- private $auth
-
Inherited from \Scrivo\Action
Inital value: \Scrivo\User::STATUS_MEMBER
View source: Action.php line 57.
- protected $context
-
Inherited from \Scrivo\Action
Inital value: null
View source: Action.php line 53.
- private $file
-
Inherited from \Scrivo\Action
Inital value: null
View source: Action.php line 59.
- private $forward
-
Inherited from \Scrivo\Action
Inital value: array()
View source: Action.php line 61.
- private array $layout
-
The layout used for rendering.
Inital value: ""
View source: LayoutAction.php line 124.
- protected $parameters
-
Inherited from \Scrivo\Action
Inital value: null
View source: Action.php line 55.
- private $result
-
Inherited from \Scrivo\Action
Inital value: self::FAIL
View source: Action.php line 62.
- private $resultData
-
Inherited from \Scrivo\Action
Inital value: null
View source: Action.php line 63.
- private array $sections
-
An array containing the all the sections defined.
Inital value: array()
View source: LayoutAction.php line 118.
- protected $session
-
Inherited from \Scrivo\Action
Inital value: null
View source: Action.php line 54.
- private array $stored
-
Stack of section options.
Inital value: array()
View source: LayoutAction.php line 112.
- private $type
-
Inherited from \Scrivo\Action
Inital value: null
View source: Action.php line 58.
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().
View source: Action.php line 121.
- 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.
View source: LayoutAction.php line 181.
- public static create(, , , )
-
Inherited from \Scrivo\Action
Parameters:
Type Name Def. Description $context $context $action $action $userStatus $userStatus $session $session View source: Action.php line 65.
- public endSection()
-
Mark the end of a layout section.
Assigns all buffered output to the section with the provided name.
View source: LayoutAction.php line 192.
- public forward()
-
Inherited from \Scrivo\Action
View source: Action.php line 149.
- public array getAllSections()
-
Retrieves all sections.
Returns:
array Retrieves all sections.
View source: LayoutAction.php line 239.
- public string getLayout()
-
Gets the currently defined layout to use for rendering.
Returns:
string Gets the currently defined layout to use for rendering.
View source: LayoutAction.php line 150.
- 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.
View source: LayoutAction.php line 229.
- public getView()
-
Inherited from \Scrivo\Action
View source: Action.php line 163.
- public getXhr()
-
Inherited from \Scrivo\Action
View source: Action.php line 171.
- public prepareXhr()
-
Inherited from \Scrivo\Action
Parameters:
Type Name Def. Description $data $data View source: Action.php line 183.
- 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.
View source: LayoutAction.php line 253.
- 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.
View source: LayoutAction.php line 161.
- public setParameters()
-
Inherited from \Scrivo\Action
Parameters:
Type Name Def. Description $arr $arr View source: Action.php line 128.
- public setResult(, =null, =null=null)
-
Inherited from \Scrivo\Action
Parameters:
Type Name Def. Description $res $res $result $result null $form_data $form_data null View source: Action.php line 132.
- 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.
View source: LayoutAction.php line 213.
- 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.
View source: LayoutAction.php line 136.
Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013



