Download the PHP package delatbabel/viewpages without Composer

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

ViewPages

StyleCI Latest Stable Version Total Downloads

Support view/rendering of Laravel pages and templates from a database.

Can be used for content management, admin interfaces (e.g. using AdminLTE or other front end frameworks), etc.

Supports loading both Blade and Twig templates using the same interface as existing view loading, for example:

Rationale

The lack of ability to have database backed views, templates, and layouts is one of the missing features that prevents Laravel from being used to create a truly dynamic CMS. This package aims to fix that.

TerrePorter partially solves this issue with his StringBladeCompiler package. His package was originally based on Flynsarmy/laravel-db-blade-compiler which did support taking a blade from a model object but is no longer maintained.

Installation

Add the package using composer from the command line:

Alternatively, pull the package in manually by adding these lines to your composer.json file:

Once that is done, run the composer update command:

Register Service Provider

After composer update completes, remove this line from your config/app.php file in the 'providers' array (or comment it out):

Replace it with this line:

Incorporate and Run the Migrations

Finally, incorporate and run the migration scripts to create the database tables as follows:

Prior to running the migration scripts you may want to alter the scripts themselves, or alter the base templates contained in database/seeds/examples. The ones provided are a few examples based on AdminLTE.

How to Use This Package

Creating Views

The important thing here is the pagekey. This basically takes the place of the view name used to find the view in the existing Laravel View facade. So, for example, if you would normally use View::make("dashboard.sysadmin"); to find the view, you would normally store the view on disk in resources/views/dashboard/sysadmin.blade.php. Instead you would store the view in the vpages table as follows:

Creating Blade Templates

You can still use templates (layouts) as you normally would in Laravel. For example, your template can contain this:

The body can then contain this:

Store the template in the vpages table with pagekey = 'layouts.main' and it will automatically be found and extended by your body view.

See Template Inheritance for more details.

Variant Content

These are website dependent data blocks, stored in the vobjects table and retrieved using the VojbecService service which can be injected into a page using Laravel Service Injection.

Example:

Twig Views and Templates

This package now supports views and templates using the Twig templating language as well as blade templates, via the TwigBridge class.

Store these in the database tables alongside your blade templates using pagetype = "twig".

Using Templates

Once the templates are created, you can use them just like any other view file, e.g.

Note that there's a bug in the Laravel View class where it uses its native factory in all cases, rather than fetching the factory from the application instance, so use the view() helper rather than the facade class like View::make().

The underlying Factory class will try to find the view by doing the following steps in order until a hit is found:

For the details on how this works, see later under "Architecture"

CMS Usage

There is an included controller class called VpageController (which you are welcome to extend) that can be used as a catch-all route. This controller contains one function called index() which simply loads a page from the database using the URL that was provided. This gives you a simple blade based CMS for your application.

To include a route to this controller, include this route specification after all of the other routes in your routes file(s):

You may need to add additional where clauses on this route to exclude other routes that your application consumes. e.g. to exclude all URLs under "/admin" and "/img" from this catch-all route, add the following where clause:

TODO

Callouts

The original package that this was derived from had the idea of callouts. This meant that views could include calls like this:

__o was a helper function that called the Controller::call() function in Laravel 3 to render the output of the "functionname" action on the toolbox controller in a HMVC like manner. HMVC is really no longer supported by Laravel 5 (and Taylor thinks that HMVC is a bad idea, which I have to disagree with) so we need some other way of pulling in dynamic content. This will probably be via Repository or Service classes somehow.

Service Injection may already work, I haven't tested it.

Architecture

I worked with a CMS system based on Laravel 3 that was fairly poor in its implementation, this package is designed to be a best practice implementation of what the Laravel 3 CMS was supposed to be.

Factory

The root of the View system is the Factory class. This is accessed by the View facade, and a view singleton which is registered in the application.

The only addition that I made to the Laravel's default Factory class was to automatically load the errors.410 view or then the errors.404 view if the requested view is not found. This is mostly of use in CMS applications where views may be searched for by URL path, and a user may enter a garbage URL so we want to put up a 404 page and not just an unhandled exception block.

Extensions and Engine Resolving

The Factory class contains an internal array called $extensions which is a mapping from a file extension (specifically a view path extension) to an engine ID. By default the array looks like this:

So the "blade.php" extension maps to the "blade" engine ID.

Additional engine extensions can be added to this $extensions array by calling Factory::addExtension(). Note that this is already done by the TwigBridge service provider

The engine ID is passed to a resolver (EngineResolver) which contains a mapping from the engine ID to the engine itself. These mappings are created in the EngineResolver::resolve() function.

So each time we return a blade template path from the database it needs to have a "blade.php" extension added to the template name so that the engine resolver can find the correct engine to compile and load the blade.

Engines

The Engine class wraps up the functionality of loading and then compiling and then evaluating the compiled template (with the data). This all happens in get(), and for blade templates more specifically (or any template that gets compiled to PHP) there is a function called evaluatePath() inside the PhpEngine class that includes the template directly and gets its output by wrapping the include statement inside an ob_start() and ob_end_clean() pair (not efficient, which is one of my reasons for disliking views that compile to PHP).

Evaluating a Twig template needs to be done differently to evaluating a Blade template because the compiled result is not directly executable. Note that this is already done in the Engine in TwigBridge.

Loading Blade Views During Compilation

The Laravel View system is somewhat backwards. The compilers each call the ViewFinders to find the files and then load the files themselves (in the compiler) rather than the file finding, loading and compiling (from string) happening independently. So this required somewhat of a re-implementation of the entire View system so that the loading stage and the compilation stage can happen separately.

Finding

This was done by:

EngineResolver needs to have the extension added to the view name in order to be able to determine the correct engine to hand the view to, so the VpageViewFinder adds the file extension to the view name. The Vpage class which loads pages from the database can strip off this file extension before loading the page in the make() function.

Note that the extension doesn't have to be prefixed with ".", it can have any prefix. The Vpage class defines the prefix to use as a constant.

Loading

Extending the compiler to include a loading stage was done by:

The final step was to extend the native Laravel BladeCompiler class to load the view contents using one of the loaders (initialised as the ChainLoader) instead of using its own internal Filesystem object to load the view contents. Compilation then happens as normal using the compileString() function.

Loading Twig Views

Finding

The ChainViewFinder class is also able to be used by the Twig loader created in the TwigBridge service provider, so that the twig loader's ViewFinder can use the same approach to finding views that the Blade loader uses.

Loading

Twig (via TwigBridge) already has the concept of a separate finder and loader class, however the loader has to follow Twig's Twig_LoaderInterface. To achieve this I built a VpageTwigLoader class to conform to the interface.

I over-rode the TwigBridge ServiceProvider class to provide a VpageTwigLoader object in the Twig_Loader_Chain object that is already used to load twig data.

Other Implementations

In modules/backend/twig, OctoberCMS has a bunch of extensions to the twig classes to do loading, etc. They have an implementaton of Twig_LoaderInterface which is still essentially a file based loader although it does a few extra Laravely things such as firing events on load, and using its own CMS classes to do things like loading files (from disk or from cache if they are present) using the Laravel File and Cache facades. This was not what I wanted to do at all.

Handling View Names

A view can be found by name or URL. A CMS may prefer to fetch views by URL, a system that is just working on view names may prefer to fetch by page key (e.g. layouts.master). The Factory class attempts to find by key first, and then by URL.

If a view is not found in the database then a view by that key is searched for on disk.

If no view is found on the disk then the errors.410 and then the errors.404 views are searched for in the database.

If no view is found at that point then an exception is thrown.

Blade Compilation

Compilation of blade templates is a bit of a black art, that's poorly explained in the Laravel documentation. Basically, blade templates are all compiled to on-disk PHP files which are then stored in storage/framework/views. Once a compiled version of a template goes out of date it is replaced with a newer copy. The caching of these compiled templates normally depends on the file date of the blade template file, however in this extension we make it depend on the updated_at date of the template data in the database.

When a blade is compiled to PHP, the directives are compiled as follows:

@extends / @section

These go together. @extends compiles to:

@section and @endsecton compile to:

Note that the directives appear in the compiled file in the opposite order to which they appear in the blade template file -- normally in the template file @extends would be at the top and @section / @endsection would be below, in the compiled template file the compiled version of @extends is at the end of the file.

@yield

@yield('section_name') appears like this in the compiled file:

Use of $__env

The global variable $__env is actually an instance of Illuminate\View\Factory.

That class implements the necessary make(), startSection(), stopSection() and yieldContent() functions, which make the content appear in the correct place.

The critical function is make() which does this:

The problem with the base Factory class is that it assumes that the view name is a file name that has an extension, and the "php" or "blade.php" or "twig" extensions can be identified to determine the view type. Instead I store the view type in the database table.

The finder and loader have been extended so that they are able to pull the view from the database instead of from disk. The logic of pulling the view from the database is all in the Vpage::make() function.

Once the content of the blade is pulled from the database and the engine is resolved then the view factory and the engine are then passed by Factory::make() to the view.

Rendering

View::render() does the actual rendering by:

Service Provider

The service provider here is fairly simple -- however there are 3:

Model Class

The model class (Vpage) replaces the on-disk storage of template files, so that the Factory class discussed above can pull templates from the database rather than disk.

References


All versions of viewpages with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
delatbabel/applog Version dev-master
delatbabel/fluents Version ~1.0
delatbabel/site-config Version dev-master
delatbabel/nestedcategories Version dev-master
illuminate/support Version ^5.1
illuminate/view Version ^5.1
rcrowe/twigbridge Version ^0.9.2
twig/twig Version 1.*
aws/aws-sdk-php Version ^3.33
league/flysystem-aws-s3-v3 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 delatbabel/viewpages contains the following files

Loading the files please wait ....