4 protected $routes = array(),
7 public function __construct () {
10 public function addRoute ($ctrlName, $incRoute = null, $default = null) {
11 if (empty ($ctrlName)) {
15 if (empty ($incRoute))
16 $incRoute = '/'.$ctrlName.'/';
19 $this->defaultRoute
= $ctrlName;
21 $this->routes
[$ctrlName] = $incRoute;
26 public function getController () {
27 $to = urldecode(tsUrl
::getRequest(NAV_VAR
));
28 // var_dump($_GET, $to);
30 if ($this->validController ($to)) {
31 return tsController
::getInstance ($to);
34 foreach ($this->routes
as $ctrlName => $regex) {
35 // var_dump($to, $ctrlName, $regex,preg_match('/'.$ctrlName.'/i', $to), preg_match($regex, $to,$a));
36 if ((preg_match('/'.$ctrlName.'/i', $to) ||
preg_match($regex, $to)) && $this->validController ($ctrlName)) {
37 return tsController
::getInstance ( $ctrlName);
41 if ($this->validController ($this->defaultRoute
))
42 return new $this->defaultRoute
;
43 // try index if it exists
44 if ($this->validController ('index'))
45 return tsController
::getInstance ('index');
49 public function validController ($ctrlName) {
50 $ctrlName = strtolower($ctrlName);
51 // var_dump($ctrlName);
53 if (!empty($ctrlName) && is_dir(PAGE_PATH
. $ctrlName) && is_file (PAGE_PATH
. $ctrlName . DIRECTORY_SEPARATOR
. $ctrlName . '.class.php')) {