ajude Theme Switcher
Enviado: 04 Mar 2012, 23:57
ola pessoal oque tem de erado nesse codigo abaixo .
na minha loja teste instalei mais não muda de template quando tento mudar , alguem pode ver oque ta errado nesse codigo .
minha loja teste é http://www.teste.shopchinacell.com/
system/engine/controller.php
<?php
abstract class Controller {
protected $registry;
protected $id;
protected $layout;
protected $template;
protected $children = array();
protected $data = array();
protected $output;
public function __construct($registry) {
$this->registry = $registry;
}
public function __get($key) {
return $this->registry->get($key);
}
public function __set($key, $value) {
$this->registry->set($key, $value);
}
protected function forward($route, $args = array()) {
return new Action($route, $args);
}
protected function redirect($url, $status = 302) {
header('Status: ' . $status);
header('Location: ' . str_replace('&', '&', $url));
exit();
}
protected function getChild($child, $args = array()) {
$action = new Action($child, $args);
$file = $action->getFile();
$class = $action->getClass();
$method = $action->getMethod();
if (file_exists($file)) {
require_once($file);
$controller = new $class($this->registry);
$controller->$method($args);
return $controller->output;
} else {
trigger_error('Error: Could not load controller ' . $child . '!');
exit();
}
}
protected function render() {
foreach ($this->children as $child) {
$this->data[basename($child)] = $this->getChild($child);
}
// Q: Theme Switcher
if (isset($this->request->get['theme']) && $this->request->get['theme'] || isset($this->session->data['theme'])) {
$directories = glob(DIR_APPLICATION . 'view/theme/*', GLOB_ONLYDIR);
$this->session->data['theme'] = (isset($this->request->get['theme']) && $this->request->get['theme']) ? $this->request->get['theme'] : $this->session->data['theme'];
foreach ($directories as $directory) {
if ($this->session->data['theme'] == basename($directory)) {
$tmp = explode('/', $filename);
$tmp[0] = $this->session->data['theme'];
$filename2 = implode('/', $tmp);
$file2 = DIR_TEMPLATE . $filename2;
if (file_exists($file2)) {
$filename = $filename2;
}
break;
}
}
}
//
if (file_exists(DIR_TEMPLATE . $this->template)) {
extract($this->data);
ob_start();
require(DIR_TEMPLATE . $this->template);
$this->output = ob_get_contents();
ob_end_clean();
return $this->output;
} else {
trigger_error('Error: Could not load template ' . DIR_TEMPLATE . $this->template . '!');
exit();
}
}
}
?>
na minha loja teste instalei mais não muda de template quando tento mudar , alguem pode ver oque ta errado nesse codigo .
minha loja teste é http://www.teste.shopchinacell.com/
system/engine/controller.php
<?php
abstract class Controller {
protected $registry;
protected $id;
protected $layout;
protected $template;
protected $children = array();
protected $data = array();
protected $output;
public function __construct($registry) {
$this->registry = $registry;
}
public function __get($key) {
return $this->registry->get($key);
}
public function __set($key, $value) {
$this->registry->set($key, $value);
}
protected function forward($route, $args = array()) {
return new Action($route, $args);
}
protected function redirect($url, $status = 302) {
header('Status: ' . $status);
header('Location: ' . str_replace('&', '&', $url));
exit();
}
protected function getChild($child, $args = array()) {
$action = new Action($child, $args);
$file = $action->getFile();
$class = $action->getClass();
$method = $action->getMethod();
if (file_exists($file)) {
require_once($file);
$controller = new $class($this->registry);
$controller->$method($args);
return $controller->output;
} else {
trigger_error('Error: Could not load controller ' . $child . '!');
exit();
}
}
protected function render() {
foreach ($this->children as $child) {
$this->data[basename($child)] = $this->getChild($child);
}
// Q: Theme Switcher
if (isset($this->request->get['theme']) && $this->request->get['theme'] || isset($this->session->data['theme'])) {
$directories = glob(DIR_APPLICATION . 'view/theme/*', GLOB_ONLYDIR);
$this->session->data['theme'] = (isset($this->request->get['theme']) && $this->request->get['theme']) ? $this->request->get['theme'] : $this->session->data['theme'];
foreach ($directories as $directory) {
if ($this->session->data['theme'] == basename($directory)) {
$tmp = explode('/', $filename);
$tmp[0] = $this->session->data['theme'];
$filename2 = implode('/', $tmp);
$file2 = DIR_TEMPLATE . $filename2;
if (file_exists($file2)) {
$filename = $filename2;
}
break;
}
}
}
//
if (file_exists(DIR_TEMPLATE . $this->template)) {
extract($this->data);
ob_start();
require(DIR_TEMPLATE . $this->template);
$this->output = ob_get_contents();
ob_end_clean();
return $this->output;
} else {
trigger_error('Error: Could not load template ' . DIR_TEMPLATE . $this->template . '!');
exit();
}
}
}
?>