Разработка для мобильных устройств
Вопрос
Это горячая тема в эти дни, и мне нужно построить шаблон на основе JQuery Mobile для моего сайта. Строите шаблон не проблема, но покажите, когда кто -то ориентируется на мобильные устройства. Я знаю, что мне нужно изменить некоторые коды в Core OC, чтобы сделать это, но мне нужны советы или помощь по этому поводу. Во -первых, место, где загружен шаблон, является /систем /гйн/controller.php. Это функция:
protected function render() {
foreach ($this->children as $child) {
$this -> data[basename($child)] = $this -> getChild($child);
}
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 {
exit('Error: Could not load template ' . DIR_TEMPLATE . $this -> template . '!');
}
}
Хорошо, я справляюсь с тем, как сработать, чтобы проверить, является ли пользовательский агент мобильным устройством или нет, и это результат:
protected function render() {
foreach ($this->children as $child) {
$this -> data[basename($child)] = $this -> getChild($child);
}
//--------- ADDED -------------------------------------------------
if ($this -> config -> get('mobile_status') == 1) {
if (($this -> isMobile() && $this -> config -> get('autodetect') == 'true') || $this -> session -> data['ismobile'] == 1) {
$mobile_template = $this -> config -> get('mobile_template_name');
if ($mobile_template != '') {
if (!function_exists('is_dir') || (function_exists('is_dir') && is_dir(DIR_TEMPLATE . $mobile_template))) {
$this -> template = $mobile_template . "/";
}
}
}
}
//--------- ADDED -------------------------------------------------
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 {
exit('Error: Could not load template ' . DIR_TEMPLATE . $this -> template . '!');
}
}
Теперь, когда я пытаюсь принять на себя acces, используя мобильный пользовательский агент, я получаю эту ошибку:
D: webserver htdocs portal/catalog/view/theme/libcommerce_mobile/warning: require (d: webserver htdocs portal catalog view theme libcommerce_mobile) [function.require]: не удалось открыть: разрешение Отказано в d: webserver htdocs portal system engine controller.php в строке 77 Фатальная ошибка: require () [function.require]: Неисправное открытие требуется 'd: webserver htdocs portal/catalog/view/ Theme/libcommerce_mobile/'(include_path ='.; D: webserver php pear ') в D: webserver htdocs portal system engine controller.php в строке 77
Но удивляет, что каталог существует, и он читается, что -нибудь помогает? Что я делаю не так? Ура еще раз
PS: выходит из этой темы, размещенную здесь http://forum.opencart.com/viewtopic.php?f=20&t=47124
Решение
Проблема в том, что $this->template
Содержит весь путь файла, а не только каталог шаблонов. Вместо этого вы должны сделать что -то подобное
if($this->config->get('mobile_status') == 1) {
if(($this->isMobile() && $this->config->get('autodetect') == 'true') || $this->session->data['ismobile'] == 1) {
$template = preg_replace('~^[^/]+~', $this->config->get('mobile_template_name'), $this->template);
if(file_exists(DIR_TEMPLATE . $template) && !is_dir(DIR_TEMPLATE . $template)) {
$this->template = $template;
}
}
}