Example #1
0
 /**
  * Inclusion d'une vue
  *
  * @param string $filename Nom du fichier
  * @param array $vars Variables spécifiques à la vue
  * @return bool
  */
 public function inc($filename, array $vars = null)
 {
     if (!strstr($filename, '.php')) {
         $filename = Router::$viewRoot . '/' . $filename . '.php';
     }
     return parent::inc($filename, $vars);
 }
Example #2
0
 protected final function inc(array $args)
 {
     $closure = new Closure();
     foreach ($args as $name => $value) {
         if (!in_array($name, array('attributes'))) {
             $closure->{$name} = $value;
         }
     }
     $closure->attributes = function (array $attributes = array()) use($args) {
         if (!isset($args['attributes'])) {
             return null;
         }
         $output = '';
         foreach ($attributes as $name => $value) {
             if (isset($args['attributes'][$name])) {
                 $args['attributes'][$name] .= ' ' . $value;
             } else {
                 $args['attributes'][$name] = $value;
             }
         }
         foreach ($args['attributes'] as $name => $value) {
             if (!Validate::isEmpty($value)) {
                 switch ($name) {
                     case 'data':
                         foreach ($value as $subname => $subvalue) {
                             $output .= ' ' . $name . '-' . $subname . '="' . trim($subvalue) . '"';
                         }
                         break;
                     default:
                         $output .= ' ' . $name . '="' . trim($value) . '"';
                         break;
                 }
             }
         }
         return $output;
     };
     $closure->attribute = function ($name) use($args) {
         if (!isset($args['attributes'])) {
             return null;
         }
         return isset($args['attributes'][$name]) ? $args['attributes'][$name] : null;
     };
     $filename = $this->getTplFile();
     if (file_exists($filename)) {
         ob_start();
         $closure->inc($filename);
         return ob_get_clean();
     } else {
         Exception::error(I18n::__('helper %s do not exists.', $filename . '.php'));
     }
     return false;
 }