[英]Opencart: call method from another controller
我需要在checkout / confirm.tpl文件中調用我在controller / product.php中創建的自定義函數
什么是最好的方法呢?
我試過這個,但不起作用:
$productController = $this->load->model('product/product');
$productController->customFunction();
$productController = $this->load->model('product/product');
Loader
有一個方法controller()
- 這不是(幸運的) 因此,假設您的控制器是CatalogProductController
,您要調用的方法是custom()
- 在這種情況下訪問此URL
http://yourstore.com/index.php?route=catalog/product/custom
您將確保調用/訪問CatalogProductController
的custom()
方法。
您可以通過多種方式訪問此類URL - 作為cURL請求,作為鏈接的href或通過AJAX請求來命名。 在PHP范圍內,即使file_get_contents()
或類似的方法也可以。
(*)我不應該意味着( 不幸的是 )它可能在OpenCart中,但這種濫用是針對MVC架構的。
是的,我終於找到了正確的答案! 對不起最后一個壞答案
class ControllerCommonHome extends Controller {
public function index() {
return $this->load->controller('product/ready');
}
}
可能是這樣的事可以幫助你(或任何有興趣的人)
// 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'])
);
他和這些不好的答案!
在laravel中它如此簡單只需編寫Controller :: call('ApplesController @ getSomething');
但是我不能做得比這更好
$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();
在這種情況下,它的呼叫產品/准備就緒
$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.