[TYPO3-dev] BE Module keeps redirecting to page 0

Stephen Bungert stephenbungert at yahoo.de
Wed Aug 3 19:00:49 CEST 2011


Hello!

I'm trying to write my first backend module... there's not much 
documentation that I can find so I'm basically started with kickstarter and 
am looking at other BE modules plus the Extension Development book from 
Dmitry Dupelov.

The kickstarter created the old style be module which I was using. I created 
4 functions and everything was working ok.

Then I discovered this article:

http://snippets.typo3.org/c/52/

And tried to make my extension have the new layout for BE modules.

After a while I got this to work... but now that I'm using the new template 
for the BE the function menu always redirects to page 0 instead of the 
current page.

Can anyone see anything that I'Äm not doing correctly?

Here is the code from my modules index.php filee
----------------------------------------------
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2011 Stephen Bungert <stephenbungert at yahoo.d.e>
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * [CLASS/FUNCTION INDEX of SCRIPT]
 *
 * Hint: use extdeveval to insert/update function index above.
 */

$LANG->includeLLFile('EXT:sb_portfolio/mod1/locallang.xml');

require_once(PATH_t3lib . 'class.t3lib_scbase.php');

$BE_USER->modAccess($MCONF, 1); // This checks permissions and exits if the 
users has no permission for entry.

// DEFAULT initialization of a module [END]



include_once(t3lib_extMgm::extPath('sb_portfolio') . 
'mod1/classes/class.tx_sbportfolio_m1base.php');
include_once(t3lib_extMgm::extPath('sb_portfolio') . 
'mod1/classes/class.tx_sbportfolio_stats.php');
include_once(t3lib_extMgm::extPath('sb_portfolio') . 
'mod1/classes/class.tx_sbportfolio_status.php');
include_once(t3lib_extMgm::extPath('sb_portfolio') . 
'mod1/classes/class.tx_sbportfolio_tags.php');
include_once(t3lib_extMgm::extPath('sb_portfolio') . 
'mod1/classes/class.tx_sbportfolio_move.php');



/**
 * Module 'SP Bortfolio' for the 'sb_portfolio' extension.
 *
 * @author Stephen Bungert <stephenbungert at yahoo.d.e>
 * @package TYPO3
 * @subpackage tx_gamebook
 */
class  tx_sbportfolio_module1 extends t3lib_SCbase {
 protected $pageinfo;
 public $modTSconfig;

 public $doc;

 /**
  * Initializes the Module
  * @return void
  */
 public function init() {
  global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;

  parent::init();

  $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id, 'mod.' . 
$this->MCONF['name']);
 }

 /**
  * Adds items to the ->MOD_MENU array. Used for the function menu selector.
  *
  * @return void
  */
 public function menuConfig() {
  global $LANG;

  $this->MOD_MENU = Array (
   'function' => Array (
    '1' => $LANG->getLL('function1'),
    '2' => $LANG->getLL('function2'),
    '3' => $LANG->getLL('function3'),
    '4' => $LANG->getLL('function4'),
   )
  );

  parent::menuConfig();
 }

 /**
  * Main function of the module. Write the content to $this->content
  * If you chose "web" as main module, you will need to consider the 
$this->id parameter which will contain the uid-number of the page clicked in 
the page tree
  *
  * @return [type]  ...
  */
 public function main() {
  global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;

  // Access check!
  // The page will show only if there is a valid page and if this page may 
be viewed by the user
  $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id, 
$this->perms_clause);
  $access = is_array($this->pageinfo) ? 1 : 0;

  if (($this->id && $access) || ($BE_USER->user['admin'] && !$this->id)) {
   $this->doc    = t3lib_div::makeInstance('template');
   $this->doc->backPath = $GLOBALS['BACK_PATH'];
   $GLOBALS['TBE_STYLES']['htmlTemplates']['mod_template.html'] = 
t3lib_extMgm::extRelPath('sb_portfolio') . 'mod1/mod_template.html';
   $this->doc->setModuleTemplate('mod_template.html');
   $this->doc->docType = 'xhtml_trans';

   #$this->doc->form = '<form action="" method="post" 
enctype="multipart/form-data">';

   $this->addJavaScript();
   $this->moduleContent();
   $this->setMarkers();

   // Setting up the buttons and markers for docheader
   $docHeaderButtons = $this->getButtons();

   $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('title'));
   $this->content.= $this->doc->moduleBody($this->pageinfo, 
$docHeaderButtons, $this->markers);
   $this->content.= $this->doc->endPage();
   $this->content = $this->doc->insertStylesAndJS($this->content);

  } else {
   // If no access or if ID == zero
  }

 }

 /**
  * Prints out the module HTML
  *
  * @return void
  */
 function printContent() {
  echo $this->content;
 }

 protected function setMarkers() {
  $this->markers = array(
   'FUNC_MENU' => $this->getFuncMenu(),
   'CONTENT' => $this->content,
   'FLASHMESSAGES' => t3lib_FlashMessageQueue::renderFlashMessages()
  );
 }

 protected function getButtons() {
  $buttons = array('shortcut' => '');

  // Shortcut
  if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
   $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 
'function',$this->MCONF['name']);
  }

  return $buttons;
 }

 protected function getFuncMenu() {
  $funcMenu = t3lib_BEfunc::getFuncMenu(
   $this->pageId,
   'SET[function]',
   $this->MOD_SETTINGS['function'],
   $this->MOD_MENU['function']
  );

  return $funcMenu;
 }

 protected function addJavaScript() {
  // JavaScript
  $this->doc->JScode = '
   <script language="javascript" type="text/javascript">
    script_ended = 0;
    function jumpToUrl(URL) {
     document.location = URL;
    }
   </script>
  ';
  $this->doc->postCode='
   <script language="javascript" type="text/javascript">
    script_ended = 1;
    if (top.fsMod) top.fsMod.recentIds["web"] = 0;
   </script>
  ';
 }

 /**
  * Generates the module content
  *
  * @return void
  */
 protected function moduleContent() {
  $modOutput = '';

  switch((string)$this->MOD_SETTINGS['function']) {
   case 1:
    $mod = t3lib_div::makeInstance('tx_sbportfolio_stats');
    $modOutput .= 
$this->doc->section($GLOBALS['LANG']->getLL('title_stats'), 
$mod->main($this, $this->modTSconfig, $this->pageinfo), 0, 1);

    break;

   case 2:
    $mod = t3lib_div::makeInstance('tx_sbportfolio_status');
    $modOutput .= 
$this->doc->section($GLOBALS['LANG']->getLL('title_status'), 
$mod->main($this, $this->modTSconfig, $this->pageinfo), 0, 1);

    break;

   case 3:
    $mod = t3lib_div::makeInstance('tx_sbportfolio_tags');
    $modOutput .= $this->doc->section($GLOBALS['LANG']->getLL('title_tags'), 
$mod->main($this, $this->modTSconfig, $this->pageinfo), 0, 1);

    break;

   case 4:
    $mod = t3lib_div::makeInstance('tx_sbportfolio_move');
    $modOutput .= $this->doc->section($GLOBALS['LANG']->getLL('title_move'), 
$mod->main($this, $this->modTSconfig, $this->pageinfo), 0, 1);

    break;
   break;
  }

  $this->content .= $modOutput;

  // For debugging
  $this->content .=    '<br />POST:' . t3lib_div::view_array($_POST) . '<br 
/>';
  $this->content .=    '<br />GET:' . t3lib_div::view_array($_GET) . '<br 
/>';

  // Add CSS
  $this->content .=  '<style type="text/css">

        .tx_sbportfolio_bePageInfo
        {
         margin-bottom: 1.0em;
        }

         table.tx_sbportfolio_bePageInfoTable
         {
          width: 100%;
         }

          .tx_sbportfolio_bePageInfoTable th,
          .tx_sbportfolio_bePageInfoTable td
          {
           text-align: center;
          }

          .tx_sbportfolio_bePageInfoTable th.leftAligned,
          .tx_sbportfolio_bePageInfoTable td.leftAligned
          {
           text-align: left;
          }

          .greyOut
          {
           color: #aaa;
          }

         .tx_sbportfolio_beOptionRow
         {
          padding: 0.5em 0.0em;
          margin-left: 0.5em;
         }

          .tx_sbportfolio_selectField
          {
           margin-right: 0.5em;
          }

          .tx_sbportfolio_selectField2
          {
           margin-left: 0.5em;
           margin-right: 0.5em;
          }

          .tx_sbportfolio_textField
          {
           margin: 0.0em 0.5em;
          }

          .tx_sbportfolio_submitField2
          {
           margin-left: 0.5em;
          }

           .tx_sbportfolio_selectField optgroup option,
           .tx_sbportfolio_selectField2 optgroup option
           {
            padding-left: 3px;
           }
       </style>';
 }
}



if (defined('TYPO3_MODE') && 
$TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sb_portfolio/mod1/index.php']) {
 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sb_portfolio/mod1/index.php']);}// Make instance:$SOBE = t3lib_div::makeInstance('tx_sbportfolio_module1');$SOBE->init();// Include files?foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);$SOBE->main();$SOBE->printContent();?>---------------------------------------------------




More information about the TYPO3-dev mailing list