Вы можете создать информационную страницу через Admin> Catalog> Information. Однако вы не сможете включить какой-либо PHP.
Чтобы создать новый шаблон, вам необходимо добавить несколько файлов в ваш проект. OpenCart основан на архитектуре MVC. Если вы не знакомы с MVC, посетите эту страницу.
http://docs.opencart.com/introduction-to-mvc-l
Контроллер:
Создайте файл с именем calculator.php и добавить его в каталог> контроллер> информацию. Затем добавьте следующее.
<?php
class ControllerInformationCalculator extends Controller {
private $error = array();
public function index() {
$this->language->load('information/calculator'); //Optional. This calls for your language file
$this->document->setTitle($this->language->get('heading_title')); //Optional. Set the title of your web page.
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/calculator'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title'); //Get "heading title" from language file.
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/calculator.tpl')) {
$this->template = $this->config->get('config_template') . '/template/information/calculator.tpl'; // If the template exists get it
} else {
$this->template = $this->config->get('config_template') . '/template/error/not-found.tpl'; //Shows an error if template not found
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
); //Required. The children files for the page.
$this->response->setOutput($this->render());
}
}
?>
Шаблон: Создайте файл с именем calculator.tpl и добавить его в каталог> вид> Тема> (Ваша тема Directory)> Шаблон> информация
Добавьте следующие строки в файл шаблона:
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
<?php } ?>
</div>
<h1><?php echo $heading_title; ?></h1>
ADD YOUR CONTENT HERE
<?php echo $content_bottom; ?></div>
<?php echo $footer; ?>
Язык: Создайте файл с именем calculator.php и добавьте его в каталог> language> english> information. Добавьте в этот файл:
<?php
// Heading
$_['heading_title'] = 'Calculator';
?>
Вы можете добавить столько переменных языка, как хотелось бы, но помните, что вам нужно, чтобы добавить их в контроллер, а также. Например:
В языковом файле:
$_['example'] = 'Example Text';
В контроллере:
$this->data['example'] = $this->language->get('example');
Если вам нужно вызвать вашу базу данных также будет нужна модель, аналогичной приведенным ниже пример. Создайте файл с именем calculator.php и добавьте в каталог> model> module.
<?php
class ModelModuleCalculator extends Model {
public function example() {
}
?>
Вам также необходимо загрузить модель, чтобы ее можно было назвать. Добавьте эту строку к контроллеру, прежде чем звонить.
$this->load->model('module/calculator');
Пример модели вызова (также в контроллере):
$this->model_module_calculator->example();
Спасибо за помощь. Я пробовал это, и он не работает. – timkeay
Контроллер и часть шаблона - это то, что я пробовал раньше, и казалось, что я пропустил один шаг, чтобы все это работало. Я создал их обоих с нуля, используя предоставленный вами контент, а также создал языковой файл. Тем не менее, не работает. – timkeay
Является ли модель частью внизу опциональной? Вы говорите «если вам нужно позвонить в вашу базу данных» ...? – timkeay