Download the PHP package peacock/view without Composer

On this page you can find all versions of the php package peacock/view. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package view

Peacock

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

Peacock is a View/Layout engine designed to make it easy to use and manipulate views without having to dive into the HTML.

Installation

composer install peacock/view

Usage

Create a view file: say_hello.php.

<p>Hello there, <?= $username ?>.</p>

Get an instance of the ViewFactory.

$viewFactory = ViewFactory::getInstance();
$viewFactory->setViewsDirectory(VIEWS_PATH);

Get a View out of the ViewFactory.

$viewData = ['username' => 'Tom'];
$view = $viewFactory->view('say_hello', $viewData);

Render the View.

$view->render();
// <p>Hello there, Tom.</p>

Using Layouts

Create a layout file: layout.php.

<html>
    <head>
    <title>Example</title>
    </head>
    <body>
        <h1>Example</h1>
        {RENDER_SECTION: content}
    </body>
</html>

Create a view file: say_hello.php.

<p>Hello there, <?= $username ?>.</p>

Get a Layout out of the ViewFactory.

$viewData = ['username' => 'Tom'];
$layout = $viewFactory->layout('layout', $viewData);

Add a child view to the layout specifying that the view content should be added to the content section, and then render the layout.

$childView = $layout->childView('say_hello', 'content');
$layout->render();

That will give the following output.

<html>
    <head>
    <title>Example</title>
    </head>
    <body>
        <h1>Example</h1>
        <p>Hello there, Tom.</p>
    </body>
</html>

Multiple Child Views & Layouts

You can add the same View/Layout multiple times.

$childView = $layout->childView('say_hello', 'content');
$childView = $layout->childView('say_hello', 'content');
$childView = $layout->childView('say_hello', 'content');
$layout->render();

That will give the following output.

<html>
    <head>
    <title>Example</title>
    </head>
    <body>
        <h1>Example</h1>
        <p>Hello there, Tom.</p>
        <p>Hello there, Tom.</p>
        <p>Hello there, Tom.</p>
    </body>
</html>

View Data

You can also pass data directly to a child view/layout.

$childView = $layout->childView('say_hello', 'content', ['username' => 'Frank']);
$childView = $layout->childView('say_hello', 'content', ['username' => 'Amelia']);
$childView = $layout->childView('say_hello', 'content', ['username' => 'Steve']);
$layout->render();

That will give the following output.

<html>
    <head>
    <title>Example</title>
    </head>
    <body>
        <h1>Example</h1>
        <p>Hello there, Frank.</p>
        <p>Hello there, Amelia.</p>
        <p>Hello there, Steve.</p>
    </body>
</html>

Child Layouts

If you want a view to add content to multiple sections then a Layout is the way to go.

Let's say we have a blog post that will show content in the main body, but also add the author's name to the footer.

layout.php

<html>
<head>
    <title>{RENDER_SECTION:title} - My Blog</title>
</head>
<body>
    <div>
        {RENDER_SECTION:main_content}
    </div>
    <footer>
        {RENDER_SECTION:footer}
    </footer>
</body>
</html>

blog_post

{SECTION:title}<?= $post->title; ?>{END_SECTION}

{SECTION:main_content}
<h1><?= $post->title; ?></h1>
<?= $post->content; ?>
{END_SECTION}

{SECTION:footer}Written by <?= $post->author; ?>{END_SECTION}

Implementation:

$post = new stdClass();
$post->title = 'How to use Peacock';
$post->author = 'Tom Wright';
$post->content = 'You should check out the GitHub README!';
$postData = ['post' => $post];

$layout = $viewFactory->layout('layout');
$layout->childLayout('blog_post', $postData);
$layout->render();

Output:

<html>
<head>
    <title>How to use Peacock - My Blog</title>
</head>
<body>
<div>

<h1>How to use Peacock</h1>
You should check out the GitHub README!
</div>
<footer>
    Written by Tom Wright
</footer>
</body>
</html>

All versions of view with dependencies

PHP Build Version
Package Version
Requires phpunit/phpunit Version ^5.4
tomwright/singleton Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package peacock/view contains the following files

Loading the files please wait ...