[英]Opencart: call method from another controller
I need to call in checkout/confirm.tpl file a custom function that i've made in controller/product.php 我需要在checkout / confirm.tpl文件中调用我在controller / product.php中创建的自定义函数
what's the best way to make this? 什么是最好的方法呢?
i've tried this, but doesn't work: 我试过这个,但不起作用:
$productController = $this->load->model('product/product');
$productController->customFunction();
$productController = $this->load->model('product/product');
controller()
in class Loader
- which is not (luckily) Loader
有一个方法controller()
- 这不是(幸运的) So let's say your controller is CatalogProductController
and the method you want to invoke is custom()
- in this case accessing this URL 因此,假设您的控制器是
CatalogProductController
,您要调用的方法是custom()
- 在这种情况下访问此URL
http://yourstore.com/index.php?route=catalog/product/custom
you will make sure that the custom()
method of CatalogProductController
is invoked/accessed. 您将确保调用/访问
CatalogProductController
的custom()
方法。
You can access such URL in many ways - as a cURL request, as a link's href or via AJAX request, to name some. 您可以通过多种方式访问此类URL - 作为cURL请求,作为链接的href或通过AJAX请求来命名。 In a PHP scope even
file_get_contents()
or similar approach will work. 在PHP范围内,即使
file_get_contents()
或类似的方法也可以。
(*) By shouldn't I mean that it is ( unfortunately ) possible in OpenCart but such abuse is against MVC architecture. (*)我不应该意味着( 不幸的是 )它可能在OpenCart中,但这种滥用是针对MVC架构的。
yes i find the right answer finally!!! 是的,我终于找到了正确的答案! sorry for last bad answer
对不起最后一个坏答案
class ControllerCommonHome extends Controller {
public function index() {
return $this->load->controller('product/ready');
}
}
May be something like this could help you (or anyone who's interested) 可能是这样的事可以帮助你(或任何有兴趣的人)
// Load seo pro
require_once(DIR_CATALOG."/controller/common/seo_pro.php"); // load file
$seoPro = new ControllerCommonSeoPro($this->registry); // pass registry to constructor
$url = HTTP_CATALOG . $seoPro->rewrite(
$this->url('information/information&information_id=' . $result['information_id'])
);
he and what these bad answers!! 他和这些不好的答案!
in laravel its so simple just write Controller::call('ApplesController@getSomething'); 在laravel中它如此简单只需编写Controller :: call('ApplesController @ getSomething');
but there i cant made better than this 但是我不能做得比这更好
$config = new Config();
// Response
$response = new Response();
$response->addHeader('Content-Type: text/html; charset=utf-8');
$response->setCompression($config->get('config_compression'));
$this->registry->set('response', $response);
$action = new Action('product/ready');
$controller = new Front($this->registry);
$controller->addPreAction(new Action('common/maintenance'));
$controller->addPreAction(new Action('common/seo_url'));
$controller->dispatch($action, new Action('error/not_found'));
$response->output();
in this case its well call product/ready 在这种情况下,它的呼叫产品/准备就绪
$this->load->controller('sale/box',$yourData);
调用框控制器的ShipmentDate()
函数
$this->load->controller('sale/box/ShipmentDate',$yourData);
return $this->load->controller('error/not_found');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.