From e073f6bf5e27d753a783e1572be6d0b207ee0d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joseba=20Ju=C3=A1niz?= Date: Mon, 21 Sep 2015 14:43:22 +0200 Subject: [PATCH] Ready added --- README.md | 41 +++++++++++++------ README_spanish.md | 101 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1c03894..72f90f2 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Yii2 Blade Layout -Routing and filtering extension system for Yii2 framework that emulates the Laravel routing system. +Blade layout extension system for Yii2 framework. ## What's Yii2 Blade Layout? -This module changes the route system definition of Yii2 in order to, instead of having to define the routes in the config file of the application now will be possible to make a series of files that hold the routes that the user will define for his web. This module lets the calling to a series of methods that will define the system routes in a more intuitive way that the basic Yii2 system getting it's inspiration from the routing system defined by Laravel. +This module adds support to Blade Layout system in your Yii2 app installation. Developed by Joseba Juániz ([@Patroklo](http://twitter.com/Patroklo)) @@ -14,11 +14,6 @@ Developed by Joseba Juániz ([@Patroklo](http://twitter.com/Patroklo)) * Yii2 -## Future plans - -* Pass manual parameters to the filters. -* Automatic system to make RESTFul Routes. - ## License This is free software. It is released under the terms of the following BSD License. @@ -55,7 +50,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * Install package via [composer](http://getcomposer.org/download/) `"cyneek/yii2-blade": "*"` * Update config file _'config/web.php'_ -``` +```php ... 'components' => [ @@ -71,13 +66,35 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ] ... ``` + + * Make a _blade_cache_ directory in your @runtime directory writable by the web user. * Profit! ## Parameters -* *cachePath* [String/Required] Directory where Blade Layout system will store the view files once they are treated. -* viewPaths [String[]/Optional] Array holding a list of directories where views and layouts will be stored. -* extension [String/Optional] It you are going to use another extension than `.blade` for your views it should be stated here. +* **cachePath** [String/Required] Directory where Blade Layout system will store the view files once they are treated. Should be writable by the web server user (for example www-data). +* **viewPaths** [String[]/Optional] Array holding a list of directories where views and layouts will be stored. This is not really necessary since the system will get the view paths once they are retrieved to the Blade Wrapper. +* **extension** [String/Optional] It you are going to use another extension than `.blade` for your view files, it should be stated here as well as in the array key of the renderers array. + +### Using the `layout` parameter + +It's possible to define the controller's parameter `layout` with a Blade file. But since the Yii2 view render system it's not 100% compatible with the Blade Layout rendering, you'll have to add a behavior to that controller called `BladeBehavior` that will integrate both systems. + +To add this behavior you'll only have to include: + + +```php + public function behaviors() + { + return [ + ... + 'blade' => [ + 'class' => BladeBehavior::className() + ], + ... + ]; + } +``` -### Basic use +Then the layout view file will be rendered before the views if both layout and view files have a blade file extension. If not, Yii2 normal rendering system will be used instead. diff --git a/README_spanish.md b/README_spanish.md index e69de29..4adcec9 100644 --- a/README_spanish.md +++ b/README_spanish.md @@ -0,0 +1,101 @@ +# Yii2 Blade Layout + +Extensión de Blade para el framework Yii2. + +## ¿Qué es Yii2 Blade Layout? + +Este módulo añade soporte al sistema de Blade Layout en nuestra aplicación de Yii2. + +Desarrollado by Joseba Juániz ([@Patroklo](http://twitter.com/Patroklo)) + +[English Readme version](https://github.com/Patroklo/yii2-blade/blob/master/README.md) + +## Minimum requirements + +* Yii2 + + +## Licencia + +Esto es software libre. Está liberado bajo los términos de la siguiente licencia BSD + +Copyright (c) 2014, by Cyneek +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. Neither the name of Cyneek nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +## Instalación + +* Instalar [Yii 2](http://www.yiiframework.com/download) +* Instalar el paque vía [composer](http://getcomposer.org/download/) `"cyneek/yii2-blade": "*"` +* Modificar el fichero config _'config/web.php'_ + +```php + +... +'components' => [ + 'view' => [ + 'class' => 'yii\web\View', + 'renderers' => [ + 'blade' => [ + 'class' => '\cyneek\yii2\blade\ViewRenderer', + 'cachePath' => '@runtime/blade_cache', + ], + ], + ], +] +... +``` + + +* Crear un directorio llamado _blade_cache_ en la raíz de @runtime que pueda ser editado por el usuario web. +* Profit! + +## Parameters + +* **cachePath** [String/Obligatorio] Directorio donde el sistema Blade almacenará las vistas una vez han sido tratads. Tiene que ser editable por el usuario web (por ejemplo www-data). +* **viewPaths** [String[]/Opcional] Array con una lista de directorios donde las vistas y layouts residen. No es necesario realmente ya que el sistema obtiene los directorios de las propias vistas y layouts y se añaden automáticamente al Wrapper de Blade. +* **extension** [String/Opcional] Si vas a usar una extensión para las vistas diferente de `.blade`, debería estar aquí también definido además de en el key del array `renderers`. + +### Usando el parámetro `layout` + +Es posible definir en el parámetro `layout` de los controllers un fichero de tipo Blade. Pero ya que el sistema de renderizado de vistas de Yii2 no es 100% compatible con el de Blade, tendrás que añadir un behavior al controller llamado `BladeBehavior` que se encargará de integrar ambos sistemas. + +Para añadir este behavior tan sólo hay que incluir en el controller: + +```php + public function behaviors() + { + return [ + ... + 'blade' => [ + 'class' => BladeBehavior::className() + ], + ... + ]; + } +``` + +Entonces el fichero layout será renderizado antes que las vistas que contiene, a diferencia del sistema estandar de Yii2, que las renderiza al final. \ No newline at end of file