[TYPO3-dev] COA_INT in extension ?

JoH info at cybercraft.de
Fri Sep 15 14:04:31 CEST 2006


>> Nothing similar - since you will do exactly the same thing in your
>> extensions:
>
> Not really. Even if one executes cObjGetSingle for COA_INT inside
> plugin, rest of the system have no idea for it and still will cache
> final output.

No - I have tested this approach thoroughly and it works perfectly fine.
As you can see the whole TS-Array is just transferred inside the userFunc.
So it doesn't make any difference if it is created this way or directly
inside the PHP code.

See it in action here:
http://www.4any1.de/www.4any1.de?id=2346
and notice the difference in the time settings when reloading the cached
version.
COA_INT will never be cached.


BTW: This approach was created to show that it is possible to split the
output of a plugin into lots of cached and non cached chunks to avoid the
ugly set_no_cache() solution.
The separate userFuncs for the different parts are not necessary but I
thought they would come in handy if you want to trigger different
functionality for a shop system.

This is the TS-Setup:

plugin.tx_cachetest_pi1 = COA
plugin.tx_cachetest_pi1 {
    10 = TEXT
    10.data = date:U
    10.strftime = %D - %H:%M:%S
    10.wrap = First Called:&nbsp;|<br /><br />
    20 = USER
    20 {
        userFunc = tx_cachetest_pi1->main
        userFunc {
            basket = COA_INT
            basket {
                wrap = <hr />|
                10 = TEXT
                10.value = Basket (COA_INT):
                20 = USER
                20.userFunc = tx_cachetest_pi1->callTimeBasket
            }
            singleView = COA
            singleView {
                wrap = <hr />|
                10 = TEXT
                10.value = Single View (COA):
                20 = USER
                20.userFunc = tx_cachetest_pi1->callTimeSingle
            }
            combinedView = COA
            combinedView {
                wrap = <hr />|
                10 = COA
                10 {
                    wrap = |<br />
                    10 = TEXT
                    10.value = CombinedView (COA) Part1 (COA):
                    20 = USER
                    20.userFunc = tx_cachetest_pi1->callTimeCombined1
                }
                20 = COA_INT
                20 {
                    wrap = |<br />
                    10 = TEXT
                    10.value = CombinedView (COA) Part2 (COA_INT):
                    20 = USER
                    20.userFunc = tx_cachetest_pi1->callTimeCombined2
                }
            }
        }
    }
}

and this is the PHP code:

<?php

require_once(PATH_tslib.'class.tslib_pibase.php');

class tx_cachetest_pi1 extends tslib_pibase {
 var $prefixId = 'tx_cachetest_pi1';  // Same as class name
 var $scriptRelPath = 'pi1/class.tx_cachetest_pi1.php'; // Path to this
script relative to the extension dir.
 var $extKey = 'cachetest'; // The extension key.
 var $pi_checkCHash = TRUE;

 /**
  * The main method of the PlugIn
  *
  * @param string  $content: The PlugIn content
  * @param array  $conf: The PlugIn configuration
  * @return The content that is displayed on the website
  */
 function main($content,$conf) {
    $this->conf=$conf;
    $this->pi_setPiVarDefaults();
    $this->pi_loadLL();
    foreach ($conf['userFunc.'] as $part => $setup) {
        if(!strpos($part,'.')) {
            $content .=
$this->cObj->cObjGetSingle($setup,$conf['userFunc.'][$part.'.']);
        }
    }
    return $this->pi_wrapInBaseClass($content);
}

function callTimeBasket() {
    return strftime('%D - %H:%M:%S',time());
}

function callTimeSingle() {
    return strftime('%D - %H:%M:%S',time());
}

function callTimeCombined1() {
    return strftime('%D - %H:%M:%S',time());
}

function callTimeCombined2() {
    return strftime('%D - %H:%M:%S',time());
}
}

if (defined('TYPO3_MODE') &&
$TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cachetest/pi1/class.tx_cachetest
_pi1.php']) {

include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cachetest/pi1/class
.tx_cachetest_pi1.php']);
}

?>

-- 
Wenn man keine Ahnung hat: Einfach mal Fresse halten!
(If you have no clues: simply shut your knob sometimes!)
Dieter Nuhr, German comedian
openBC: http://www.cybercraft.de
T3 cookbook: http://www.typo3experts.com






More information about the TYPO3-dev mailing list