public function renderForm(array $htmlOptions = []) : string { if (isset(static::$schema['template'])) { $dir = dirname(static::$schema['template']); $template = basename(static::$schema['template']); } else { $reflector = new \ReflectionClass(static::class); $filename = $reflector->getFileName(); $dir = dirname($filename); $template = pathinfo(basename($filename), PATHINFO_FILENAME) . '.html'; } $view = new View('Twig'); $view->addTemplateRawPath($dir); return $view->render($template, ['filters' => $this, 'html' => $htmlOptions]); }
public function renderFormElement(array $htmlOptions = []) : string { if (isset($this->options['template'])) { $dir = dirname($this->options['template']); $template = basename($this->options['template']); } else { $reflector = new \ReflectionClass(static::class); $filename = $reflector->getFileName(); $dir = dirname($filename); $template = pathinfo(basename($filename), PATHINFO_FILENAME) . '.html'; } $view = new View('Twig'); $view->addTemplateRawPath($dir); $props = []; foreach (array_keys(get_object_vars($this)) as $prop) { $props[$prop] = $this->{$prop}; } return $view->render($template, $props + ['html' => $htmlOptions]); }
/** * @param string $module * @param string $controller * @throws \T4\Core\Exception * @return \T4\Mvc\Controller */ public function createController($module = null, $controller) { if (!$this->existsController($module ?: null, $controller)) { throw new Exception('Controller ' . $controller . ' does not exist'); } if (empty($module)) { $controllerClass = '\\App\\Controllers\\' . $controller; } else { $controllerClass = '\\App\\Modules\\' . ucfirst($module) . '\\Controllers\\' . ucfirst($controller); } $controller = new $controllerClass(); $view = new View('twig', $controller->getTemplatePaths()); $controller->view = $view; $view->setController($controller); return $controller; }