Ver Mensaje Individual
  #17 (permalink)  
Antiguo 31/03/2015, 15:18
Avatar de Chiiviito
Chiiviito
 
Fecha de Ingreso: octubre-2012
Mensajes: 64
Antigüedad: 11 años, 6 meses
Puntos: 0
Respuesta: Necesito saber como ejecutar funcion desde TWIG

Este es mi codigo limpio:
Código PHP:
Ver original
  1. <?php
  2. require_once 'Twig/Autoloader.php';
  3.  
  4. Twig_Autoloader::register();
  5.  
  6. $loader = new Twig_Loader_Filesystem('templates');
  7.  
  8. $twig = new Twig_Environment($loader, array(
  9.             'cache' => 'cache',
  10.             'debug' => 'true'));
  11.  
  12. $template = $twig->loadTemplate('index.twig.html');
  13.  
  14. echo $template->render(array(
  15.     'variable'  =>  'Hola mundo!',
  16.     ));

Asi quedo luego de leer la guia:
Código PHP:
Ver original
  1. <?php
  2. require_once 'Twig/Autoloader.php';
  3.  
  4. Twig_Autoloader::register();
  5.  
  6. $loader = new Twig_Loader_Filesystem('templates');
  7.  
  8. $twig = new Twig_Environment($loader, array(
  9.             'cache' => 'cache',
  10.             'debug' => 'true'));
  11. /*---------------*/
  12. $function = new Twig_SimpleFunction('funciontestmia', function () {
  13.     return 'VARIABLE TEST';
  14. });
  15. /*-------------*/
  16. $template = $twig->loadTemplate('index.twig.html');
  17.  
  18. $twig->addFunction($function); // Agrega la funcion
  19.  
  20. echo $template->render(array(
  21.     'variable'  =>  'Hola mundo!',
  22.     ));

El error es el siguiente:
Código PHP:
Ver original
  1. Fatal error: Class 'Twig_SimpleFunction' not found in C:\xampp\htdocs\1\index.php on line 12

Osea la clase Twig_SimpleFunction es como si no existiera