1. Go to this page and download the library: Download shinigamicorei7/view library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shinigamicorei7 / view example snippets
return array(
/**
* Este campo es obligatorio ya que se usará como directorio root de las plantillas
*
* templates_dir string|array
*/
'templates_dir' => array(
'path/to/templates/'
),
/**
* Namespaces que se usaran en la aplicación Ej:
*
* echo view('@namespace/index.twig',$data);
* o
* echo View::render('@namespace/index.twig',$data);
*
* namespaces null|array
*/
'namespaces' => array(
'test' => 'path/to/test/views/'
),
/**
* Opciones diponibles
*
* @see \Twig_Environment
* options array
*/
'options' => array(
'debug' => false,
'cache' => 'path/to/cache/'
)
);
View::setDirConfig('path/to/view/config.php');
/**
* Usando la sobrecarga de clases
*/
echo View::render('index.twig',array('nombre' => 'Shinigamicorei7'));
/**
* Usando la función de ayuda
* echo view('index.twig',array('nombre' => 'Shinigamicorei7'));
*/
/**
* Usando los namespaces definidos en nuestro archivo de configuración
* echo view('@test/index.twig',array('nombre' => 'Shinigamicorei7'));
*/
/**
* is_a es una función del core de php, por esa razón la invocamos con una cadena de texto
*/
$is_a = new Twig_SimpleFunction('is_a', 'is_a');
$filter = new Twig_SimpleFilter('array_filter', function ($context, $string) {
//tu código
}, array('needs_context' => true));
$test = new Twig_SimpleTest('red', function ($value) {
if (isset($value->color) && $value->color == 'red') {
return true;
}
if (isset($value->paint) && $value->paint == 'red') {
return true;
}
return false;
});
View::addFunction($is_a);
View::addFilter($filter);
View::addTest($test);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.