Skip to content

Commit

Permalink
Merge branch '3.0.x' into 2.35.x-merge-up-into-3.0.x_ycpcjD6g
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.lock
#	psalm-baseline.xml
#	src/Helper/Json.php
#	src/Renderer/PhpRenderer.php
#	test/Helper/JsonTest.php
  • Loading branch information
gsteel committed Jun 4, 2024
2 parents f597148 + ab2c6f9 commit 58e2a61
Show file tree
Hide file tree
Showing 65 changed files with 5,273 additions and 2,224 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

[![Build Status](https://github.com/laminas/laminas-view/workflows/Continuous%20Integration/badge.svg)](https://github.com/laminas/laminas-view/actions?query=workflow%3A"Continuous+Integration")

> ## 🇷🇺 Русским гражданам
>
> Мы, участники Laminas, родились и живем в разных странах. У многих из нас есть друзья, родственники и коллеги как в России, так и в Украине. Некоторые из нас родились в России. Некоторые из нас живут в России. У некоторых бабушки и дедушки сражались с фашистами во Второй мировой войне. Здесь никто не поддерживает фашизм.
>
> У одного из нас есть украинская родственница, которая спаслась из дома вместе с сыном. Поезд задержался из-за бомбежки на дороге впереди. У нас есть друзья, которые прячутся в бомбоубежищах. Мы с тревогой ждем весточки от них после воздушных налетов, которые беспорядочно наносят удары и попадают по больницам, школам, детским садам и домам. Мы не берем это из каких-либо СМИ. Мы наблюдаем это напрямую.
>
> Вы доверяете нам достаточно, чтоб использовать наши программы, и мы просим вас довериться нам вновь. Мы нуждаемся в помощи. Выходите и протестуйте против этой бесполезной войны. Остановите кровопролитие. Скажите "Нет войне!"
>
> ## 🇺🇸 To Citizens of Russia
>
> We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
>
> One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
>
> You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"
laminas-view provides the “View” layer of the Laminas MVC system. It is a
multi-tiered system allowing a variety of mechanisms for extension,
substitution, and more.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"php": "8.1.99"
},
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"composer/package-versions-deprecated": true
}
},
"require": {
Expand All @@ -46,7 +47,6 @@
"laminas/laminas-modulemanager": "^2.15",
"laminas/laminas-mvc": "^3.7.0",
"laminas/laminas-mvc-i18n": "^1.8",
"laminas/laminas-mvc-plugin-flashmessenger": "^1.10.1",
"laminas/laminas-navigation": "^2.19.1",
"laminas/laminas-paginator": "^2.18.1",
"laminas/laminas-permissions-acl": "^2.16",
Expand Down
210 changes: 210 additions & 0 deletions docs/book/v3/application-integration/stand-alone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# Stand-Alone

The view and all view-helpers of laminas-view can also be used stand-alone.

## The View

The examples uses the following directory structure:

```treeview
./
|-- public/
| `-- index.php
`-- templates/
|-- index.phtml
`-- layout.phtml
```

### Basic Example

#### Setup

[Create a renderer, set a resolver for templates](../php-renderer.md#usage)
and initialize the view in `public/index.php`:

```php
// Create template resolver
$templateResolver = new Laminas\View\Resolver\TemplatePathStack([
'script_paths' => [__DIR__ . '/../templates'],
]);

// Create the renderer
$renderer = new Laminas\View\Renderer\PhpRenderer();
$renderer->setResolver($templateResolver);

// Initialize the view
$view = new Laminas\View\View();
$view->getEventManager()->attach(
Laminas\View\ViewEvent::EVENT_RENDERER,
static function () use ($renderer) {
return $renderer;
}
);
```

#### Create View Script

[Create a view script](../view-scripts.md) in `templates/index.phtml`:

```php
<?php
/**
* @var Laminas\View\Renderer\PhpRenderer $this
* @var string $headline
*/
?>
<h1><?= $headline ?></h1>
```

#### Create View Model and render Output

Extend the script in `public/index.php` to add a [view model](../quick-start.md):

```php
$viewModel = new Laminas\View\Model\ViewModel(['headline' => 'Example']);
$viewModel->setTemplate('index');

// Set the return type to get the rendered content
$viewModel->setOption('has_parent', true);

echo $view->render($viewModel); // <h1>Example</h1>
```
<!-- markdownlint-disable-next-line no-inline-html -->
<details><summary>Show full code example</summary>

```php
<?php

require_once __DIR__ . '/../vendor/autoload.php';

// Create template resolver
$templateResolver = new Laminas\View\Resolver\TemplatePathStack([
'script_paths' => [__DIR__ . '/../templates'],
]);

// Create the renderer
$renderer = new Laminas\View\Renderer\PhpRenderer();
$renderer->setResolver($templateResolver);

// Initialize the view
$view = new Laminas\View\View();
$view->getEventManager()->attach(
Laminas\View\ViewEvent::EVENT_RENDERER,
static function () use ($renderer) {
return $renderer;
}
);

// Create view model
$viewModel = new Laminas\View\Model\ViewModel(['headline' => 'Example']);
$viewModel->setTemplate('index');

// Set the return type to get the rendered content
$viewModel->setOption('has_parent', true);

// Render
echo $view->render($viewModel);
```

<!-- markdownlint-disable-next-line no-inline-html -->
</details>

### Example with Layout

#### Add Layout Script

Create a new file `templates/layout.phtml` and add the following content:

```php
<?php
/**
* @var Laminas\View\Renderer\PhpRenderer $this
* @var string $content
*/
?>
<body>
<?= $content ?>
</body>
```

#### Create Layout Model and render Output

Update the script in `public/index.php` to add a view model for layout:

```php
// Create layout model
$layout = new Laminas\View\Model\ViewModel();
$layout->setTemplate('layout');

// Set the return type to get the rendered content
$layout->setOption('has_parent', true);

// Add previous view model as child
$layout->addChild($viewModel);

// Render
echo $view->render($layout);
```

<!-- markdownlint-disable-next-line no-inline-html -->
<details><summary>Show full code example</summary>

```php
<?php

require_once __DIR__ . '/../vendor/autoload.php';

// Create template resolver
$templateResolver = new Laminas\View\Resolver\TemplatePathStack([
'script_paths' => [__DIR__ . '/../templates'],
]);

// Create the renderer
$renderer = new Laminas\View\Renderer\PhpRenderer();
$renderer->setResolver($templateResolver);

// Initialize the view
$view = new Laminas\View\View();
$view->getEventManager()->attach(
Laminas\View\ViewEvent::EVENT_RENDERER,
static function () use ($renderer) {
return $renderer;
}
);

// Create view model
$viewModel = new Laminas\View\Model\ViewModel(['headline' => 'Example']);
$viewModel->setTemplate('index');

// Create layout model
$layout = new Laminas\View\Model\ViewModel();
$layout->setTemplate('layout');

// Set the return type to get the rendered content
$layout->setOption('has_parent', true);

// Add previous view model as child
$layout->addChild($viewModel);

// Render
echo $view->render($layout);
```

<!-- markdownlint-disable-next-line no-inline-html -->
</details>

## View Helpers

### Setup

Create the renderer:

```php
$renderer = new Laminas\View\Renderer\PhpRenderer();
```

### Using Helper

```php
echo $renderer->doctype(Laminas\View\Helper\Doctype::HTML5); // <!DOCTYPE html>
```
Loading

0 comments on commit 58e2a61

Please sign in to comment.