Save data created in OpenCart 2.3 event for later display

浪尽此生 提交于 2019-12-24 10:37:00

问题


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.

How have other people handled this?


回答1:


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));

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));
}

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.



来源:https://stackoverflow.com/questions/44622991/save-data-created-in-opencart-2-3-event-for-later-display

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!