Re: icmsOnDemandPreload - what is it and how does it work?

Posted by marcan on 1266409785
The icmsOnDemandPreload concept is to be able to load preload code on demand, when we want it.

As we know, adding a file in htdocs/plugins/preloads will add code somewhere in the bootstrap process. But this code will be executed all the time. Sometimes, we don't want this. We only want to add code somewhere in the bootstrap, but on some specific occasion.

In the case you are referring too, imBlogging, we need to "link" to imTagging module as it's the module taking care of the categories of imBlogging. The admin create/edit post page in imBlogging is displaying a category control powered by imTagging, and this needs jQuery and CSS, both already defined in imTagging.

(Today, there would be a better way to include this code, but at the time, it was teh best way, and a good demonstration of IcmsOnDemandPreload).

So how does IcmsOnDemandPreload works ? Simply by defining an array before mainfile.php is included. This is what we do in imblogging/admin/post.php:

$icmsOnDemandPreload[] = array( 'module'=>'imtagging', 'filename'=>'jquery.php' ); $icmsOnDemandPreload[] = array( 'module'=>'imtagging', 'filename'=>'imtaggingadmincss.php' ); include_once("admin_header.php");

The array need to be named $icmsOnDemandPreload and each item of this array is another array with 2 info:

1- In what module shall we find the preload item
2- what is the preload filename

In this case, we are defining 2 preload item to be loaded:

1- modules/imtagging/preload/jquery.php
2- modules/imtagging/preload/imtaggingadmincss.php

So that's it for ccmsOnDemandPreload.

Quote:

I think 2 different approaches were made for preloads and they now conflict with each other. Who can explain and improve this?


No, it's the same approach. We can see it in kernel/icmspreloadhandler.php, in the constructor, we are checking for an array named icmsOnDemandPreload:
function IcmsPreloadHandler() { $preloadFilesArray = XoopsLists::getFileListAsArray(ICMS_PRELOAD_PATH); foreach ($preloadFilesArray as $filename) { // exclude index.html if ($filename != 'index.html') { $this->_preloadFilesArray[] = $filename; $this->addPreloadEvents($filename); } } // add ondemand preload global $icmsOnDemandPreload; if (isset($icmsOnDemandPreload) && count($icmsOnDemandPreload) > 0) { foreach ($icmsOnDemandPreload as $onDemandPreload) { $this->_preloadFilesArray[] = $onDemandPreload['filename']; $this->addPreloadEvents($onDemandPreload['filename'], $onDemandPreload['module']); } } }

Now, why would this create a blank page, this is another question. Perhaps another thread should be opened to discuss this bug ?

Any question, please ask!

This Post was from: https://www.impresscms.org/iforum/viewtopic.php?topic_id=4080&post_id=36783