本文介绍了保存在OpenCart 2.3事件中创建的数据以供以后显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解了如何使用事件在OpenCart 2.3中生成控制器调用.

I see how to use an event to generate a controller call in OpenCart 2.3.

我看不到如何保存由控制器调用创建的数据,以供以后在视图中使用.

What I don't see is how to save the data created by the controller call for later use in a view.

其他人如何处理?

推荐答案

不确定确切要在这里做什么,但不能仅仅做类似的事情:

Not sure exactly what you want to do here but couldn't you just do something like:

file_put_contents(DIR_CACHE . __CLASS__ . __FUNCTION__ . md5(serialize($this->request->get)) . '.ser', serialize($data));

这会将所有内容存储在以类,方法和查询参数命名的平面文件中的$data中(即传递给视图的所有内容).

That would store everything in $data (which is everything that gets passed to the view) in a flat file named after the class and method and query parameters.

然后,例如,稍后在产品页面上回想一下,只需执行以下操作:

Then, for example, to recall later on a product page, just do:

if (file_exists(DIR_CACHE . __CLASS__ . __FUNCTION__ . md5(serialize($this->request->get)) . '.ser') {
    $data = unserialize(file_get_contents(DIR_CACHE . __CLASS__ . __FUNCTION__ . md5(serialize($this->request->get)) . '.ser'));
    $this->response->setOutput($this->load->view('product/product', $data));
}

不确定是否能回答您的问题,但是如果您希望Opencart定期失效,也可以使用Opencart的内置缓存方法.

Not sure if that answers your question but could could also just use Opencart's built in cache methods if you wanted it to expire at regular intervals.

这篇关于保存在OpenCart 2.3事件中创建的数据以供以后显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 11:49