PHP Template Engine built by url -
i searching kind of dynamic template engine want built url. if url localhost/root/this/is/the/path/to/signup.php php code should watch file signup.php in directory this/is/the/path/to/
for time using arrays of url following code shows:
$url = isset($_get['url']) ? $_get['url'] : null; $url = rtrim($url, '/'); $url = explode('/', $url); if (empty($url[0])) { $url[0] = "path/startpage.php"; } if (isset($url[2])) { require "path/error.php"; } else if (isset($url[1])) { $file1 = 'path/' .$url[0].'/'.$url[1].'/'.$url[1].'.php'; if (file_exists($file1)) { require $file1; } else { require "error.php"; } } else if (isset($url[0])) { $file0 = 'path/'.$url[0].'/'.$url[0].'.php'; if (file_exists($file0)) { require $file0; } else { require "path/error.php"; } }
but script have every case , not nice. want have solution code looking whole url, goes directory , require error or file, if exists.
could me please?
the titon\view library handles quite easily: https://github.com/titon/view
if array of paths passed in template, generate dynamic lookup paths. https://github.com/titon/view/blob/master/src/titon/view/view.php#l127
example:
$view = new titon\view\view(); $view->addpath('/path/to/views/'); $parsed = $view->run(['path', 'to', 'lookup/folder', 'templatename]);
can take @ tests see in action: https://github.com/titon/view/blob/master/tests/titon/view/viewtest.php
Comments
Post a Comment