[TYPO3] menuFunc

Peter Klein peter at umloud.dk
Mon Jul 9 11:15:12 CEST 2007


Hi Bas. Here's an updated version of the PHP script, and a new example 
Typoscript, that tells the PHP script to look for a GET var, and use that 
value to determine which "page" should be set to active.

The new PHP class/function
-- cut --
<?php

class user_menuFunc {

 function makeMenuArray($content,$conf) {
  $menuArr = array();
  $lConf = $conf["userFunc."];
  $actuid = 0;
  if ($lConf['actextkey'] && $lConf['actextvar']) {
   $getval = t3lib_div::_GET();
   $actuid = $getval[$lConf['actextkey']][$lConf['actextvar']];
  }
  $res = $this->cObj->exec_getQuery($lConf["table"],$lConf["select."]);
  if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
   $GLOBALS['TT']->setTSlogMessage($error,3);
  }
  else {
   $GLOBALS['TT']->setTSlogMessage('NUMROWS: 
'.$GLOBALS['TYPO3_DB']->sql_num_rows($res));
   while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
    if ($actuid!=0 && $actuid==$row['uid']) $row['ITEM_STATE']='ACT';
    $menuArr[] = $row;
   }
  }
  return $menuArr;
 }

}

?>
-- cut --

The new Typoscript Example:
-- cut --
page.includeLibs.menustuff = fileadmin/menuFunc2.inc

obj.header = HMENU
obj.header.special = userfunction
obj.header.special.userFunc = user_menuFunc->makeMenuArray
obj.header.special.userFunc.table = tx_ablinklist_category
obj.header.special.userFunc.select.pidInList = 91
obj.header.special.userFunc.actextkey = tx_ablinklist_pi1
obj.header.special.userFunc.actextvar = category_uid
obj.header.1 = TMENU
obj.header.1 {
   NO {
     doNotLinkIt = 0
     stdWrap.field = label
     stdWrap.typolink.useCacheHash = 1
     stdWrap.typolink.parameter.data = page:uid
     stdWrap.typolink.additionalParams.dataWrap = 
&tx_ablinklist_pi1[category_uid]={field:uid}
     #stdWrap.data = debug:data
     allWrap = |<br>
   }
   ACT < .NO
   ACT = 1
   ACT.allWrap = <b>|</b><br>
}

page.7911 < obj.header
-- cut --

In the Typoscript for the userFunc, you can now set 2 extra parameters:

obj.header.special.userFunc.actextkey = tx_ablinklist_pi1
Which sets the extension key of the GET var that should be used to determine 
the ACT state.

And:

obj.header.special.userFunc.actextvar = category_uid
Which sets the extension variable of the GET var that should be used to 
determine the ACT state.


-- 
Peter Klein/Umloud Untd

"Bas van der Togt" <bas.vander.togt at efocus.nl> skrev i en meddelelse 
news:mailman.1.1183730990.23655.typo3-english at lists.netfielders.de...
> Thank you for your answer Peter!
>
> I'm not an php expert.
> Can you maybe give me an example?
>
> <?php
> class user_menuFunc2 {
> function makeMenuArray($content,$conf) {
> $menuArr = array();
> $lConf = $conf["userFunc."];
> $res = $this->cObj->exec_getQuery($lConf["table"],$lConf["select."]);
>
> if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
> $GLOBALS['TT']->setTSlogMessage($error,3);
> }
>
> else {
> $GLOBALS['TT']->setTSlogMessage('NUMROWS: 
> '.$GLOBALS['TYPO3_DB']->sql_num_rows($res));
> while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
> $menuArr[] = $row;
> }
> }
>
> return $menuArr;
> }
> }
> ?>
>
> Peter Klein wrote:
>> Hi Bas. If you want to set the ACT state for one of the menu items, you 
>> can do it like this in your userFunc.
>> But you have to specify which menuitem ($k) it is you want active 
>> yourself.
>>
>>  $menuArr[$k]["ITEM_STATE"]="ACT";
>> 




More information about the TYPO3-english mailing list