Download the PHP package jasny/view without Composer

On this page you can find all versions of the php package jasny/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

Jasny View

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight Packagist Stable Version Packagist License

An abstraction for using PSR-7 with template engines.

Jasny View isn't bound to any framework and can be used anywhere you want to use an existing template engine like Twig with PSR-7.

Installation

Install using composer

composer require jasny\view

Usage

All view layers of Jasny View implement the Jasny\ViewInterface, which defines the following methods:

Expose

Expose a function to the view. This can be a build-in PHP function, a user defined function or even an anonymous function.

expose(string $name, callable $function = null);

You may omit the second argument. In that case, the name will be used as function name.

Render

Render and output a template. Outputting is done by writing the result to the response body and setting the response Content-Type header.

render(ResponseInterface $response, string $name, array $context = []);

The name is the name of the template and usually corresponds with a filename. The context are the values that are made available to the view (as variable or constant).

Twig

Jasny\View\Twig is a wrapper around Twig_Environment. When creating the view object, you can either specify the options to create an environment or pass a Twig environment.

The path option is required. It's passed to the Twig_Loader_Filesystem and serves as the base directory where the view files are located.

Other options are passed the constructor when creating a Twig_Environment. The following options are available:

Passing a Twig_Environment is recommended if your applicated focusses on Dependency Injection.

getTwig

The getTwig() method returns the Twig_Environment object it wraps. It can be used to extends the twig environment.

addDefaultExtensions

Calling $view->addDefaultExtensions() will add all Official Twig extensions and Jasny Twig extensions if available.

expose

For Twig, expose optionally takes a third argument. You can specify if the function should be added as Twig function or Twig filter.

expose($name, $function = null, $as = 'function')

render

Render will automatically add .html.twig to the name, if the name doesn't contain an extension. It calls the render method of the Twig environment and write the redered content to the response body.

PHP

The PHP layer doesn't use template rendering engine, but simply includes a PHP file.

The constructor takes an array of options, which must contain a path property. This is the path to the directory where the view files are located.

Optionally the ext option may be passed. This determines the default extension for the view name for render().

getPath

Get the directory path.

getExt

Get the default extension.

expose

It's typically not needed to call expose. Global PHP functions (build-in or user defined) are already available. Adding a function as alias (so $name is not the same as $template, is not availabe.

render

The render() method will include the specified template file using include. In the same context, the $context is extracted, so everything is available as variable in the view.

The output is streamed to the response body, using an output buffer callback.

If the specified file name is a directory the index file from that directory is automatically used. If the file doesn't exist, a RuntimeExpection is thrown.

Related libraries


All versions of view with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.0
psr/http-message 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 jasny/view contains the following files

Loading the files please wait ....