【发布时间】:2014-08-25 12:18:25
【问题描述】:
我需要在 checkout/confirm.tpl 文件中调用我在 controller/product.php
中创建的自定义函数最好的方法是什么?
我试过了,但是不行:
$productController = $this->load->model('product/product');
$productController->customFunction();
【问题讨论】:
我需要在 checkout/confirm.tpl 文件中调用我在 controller/product.php
中创建的自定义函数最好的方法是什么?
我试过了,但是不行:
$productController = $this->load->model('product/product');
$productController->customFunction();
【问题讨论】:
是的,我终于找到了正确的答案!!!抱歉最后一个不好的答案
class ControllerCommonHome extends Controller {
public function index() {
return $this->load->controller('product/ready');
}
}
【讨论】:
$this->load->controller('product/ready', array('foo'=>'bar')) 传递并在控制器中以public function index($args) 的形式访问它们。
$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 架构的。
【讨论】:
$this->load->controller('sale/box',$yourData);
调用盒子控制器的ShipmentDate()函数
$this->load->controller('sale/box/ShipmentDate',$yourData);
【讨论】:
可能这样的事情可以帮助你(或任何感兴趣的人)
// 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'])
);
【讨论】:
return $this->load->controller('error/not_found');
【讨论】:
在 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();
在这种情况下,它很好地调用product/ready
【讨论】: