[英]How to call a controller from a view in opencart?
I'm new to opencart.我是 opencart 的新手。 I want to create a custom theme and some custom controllers and models.
我想创建一个自定义主题和一些自定义控制器和模型。 I can't find any tutorials relative to this, but I tried to create a view along a controller.
我找不到任何与此相关的教程,但我尝试沿控制器创建视图。 When I call that view from home or header view page, like
$header
(in home file) and $search
(in header file), then it shows undefined variable.当我从主页或标题视图页面调用该视图时,例如
$header
(在主页文件中)和$search
(在头文件中),它会显示未定义的变量。
My code looks like this.我的代码看起来像这样。 It's in controller (path is
catalog\\controller\\common\\test.php
).它在控制器中(路径是
catalog\\controller\\common\\test.php
)。
<?php
class ControllerCommonTest extends Controller{
public function index() {
if(file_exists(DIR_TEMPLATE.this->config->get('config_template').'/template/test/test.tpl')) {
$this->response->setOutput($this->render());
} else {
return $this->load->view('default/template/common/header.tpl');
}
}
}
?>
And my view is in \\view\\theme\\MyTheme\\template\\common\\test.tpl
我的观点是在
\\view\\theme\\MyTheme\\template\\common\\test.tpl
<?php
echo "Test file";
?>
And in my home file, I call my controller like below...在我的主文件中,我像下面这样调用我的控制器......
<?php
echo $header;
echo $test;
echo $footer;
?>
When I run this it shows the below error:当我运行它时,它显示以下错误:
Notice: Undefined variable: test in C:\\xampp\\htdocs\\opencart\\catalog\\view\\theme\\MyCustome\\template\\common\\home.tpl on line 4
注意:未定义变量:在 C:\\xampp\\htdocs\\opencart\\catalog\\view\\theme\\MyCustome\\template\\common\\home.tpl 中第 4 行测试
So, please provide any tutorial links and any examples for developing a custom module in opencart.因此,请提供在 opencart 中开发自定义模块的任何教程链接和任何示例。
Thanks in advance.提前致谢。
To display test module tpl ie test.tpl
on home page, You have load test controller on home controller.要在主页上显示测试模块 tpl 即
test.tpl
,您在主控制器上有负载测试控制器。 Please add following code in catalog/controller/common/home.php
请在
catalog/controller/common/home.php
添加以下代码
add this code添加此代码
$data['test'] = $this->load->controller('common/test');
After后
$data['header'] = $this->load->controller('common/header');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.