Download the PHP package mfn/laravel-view-obj without Composer

On this page you can find all versions of the php package mfn/laravel-view-obj. 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 laravel-view-obj

Laravel object based view templates

Homepage: https://github.com/mfn/php-laravel-view-obj

Requirements

PHP 5.5 / Laravel 5.0/5.1

Install / Setup

Using composer: composer.phar require mfn/laravel-view-obj 0.1

Register the service provider in your config/app.php by adding this line to your providers entry: Mfn\Laravel\ViewObj\Provider::class

Publish the configuration:

php artisan vendor:publish --provider="Mfn\Laravel\ViewObj\Provider"

Documentation

This package leverages an objects class hierarchy to turn it into a path for a view template, i.e. if you want to "view" an object of type App\Article, the provided helper view_obj() will try to render the view _view_obj.App.Article.default which usually maps to your path <PROJECT_ROOT>/resources/views/_view_obj/App/Article/default.php (or default.blade.php). The object itself will be passed to that view as $obj.

Conceptually you can think of it as a partial, where the name of the view is derived from the objects class hierarchy. Views itself can be hierarchically organized by virtue of the filesystem, so can classes. This package re-uses that information for views.

The idea is that an object has different representations, depending on the context. By default the context is "default" (...), but if you want to render $article as part of a list, you create an appropriate list template and call the helper with @view_obj($article, 'list'). So, ideally, all variants how App/Article is going to be represented in the system are in this one directory, _view_obj/App/Article/.

The signature of the helper is:

view_obj(object $object, string $template = 'default', array $data = []): View

For Blade, the directive @view_obj is provided with the same signature but it will already echo the returned View, whereas in pure PHP code you receive a View object and need act on it yourself (e.g. echo ... or ->__toString()).

For convenience sake, the helper just accepts (object $object, array $data), i.e. you can omit the $template for the default case.

Examples

In the most simple case, show the default view of the object. Assuming the class App\Article, we first create the default template in resources/views/_view_obj/App/Article/default.blade.php:

Example of such a view:

Note: the object we render always gets passed as $obj

Anywhere in a view where you pass on the article, you can invoke the view with:

We now assume you want to render the article as part of a list, i.e. you have an array of articles. We first create a list template for the article in resources/views/_view_obj/App/Article/list.blade.php. We usually only display the link/title in the list:

Now using the list view:

Configuration

Contribute

Fork it, hack on a feature branch, create a pull request, be awesome!

No developer is an island so adhere to these standards:

© Markus Fischer [email protected]


All versions of laravel-view-obj with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5
illuminate/support Version 5.0.x|5.1.x
illuminate/view Version 5.0.x|5.1.x
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 mfn/laravel-view-obj contains the following files

Loading the files please wait ....