Russian TYPO3 community

Russian TYPO3 community (http://forum.typo3.ru/index.php)
-   Разработка расширений / TYPO3 extension development (http://forum.typo3.ru/forumdisplay.php?f=38)
-   -   Использование функций класса class.tx_ttnews.php в своем расширении (http://forum.typo3.ru/showthread.php?t=9470)

shuman 16.05.2011 13:31

Использование функций класса class.tx_ttnews.php в своем расширении
 
При создании своего расширения нужно составить список категорий новостей.

Это простая задача, если не брать во внимание подкатегории.

Для учета подкатегорий решил подключить класс class.tx_ttnews.php и заюзать полезную функцию initCategoryVars:

PHP код:

<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2011 
*  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.
 */

require_once(PATH_tslib.'class.tslib_pibase.php');
require_once(
t3lib_extMgm::extPath('tt_news') . 'pi/class.tx_ttnews.php');


/**
 * Plugin 'tt_news_change_picture' for the 'tt_news_change_image' extension.
 *
 * @author    
 * @package    TYPO3
 * @subpackage    tx_ttnewschangeimage
 */
class tx_ttnewschangeimage_pi1 extends tslib_pibase {
    var 
$prefixId      'tx_ttnewschangeimage_pi1';        // Same as class name
    
var $scriptRelPath 'pi1/class.tx_ttnewschangeimage_pi1.php';    // Path to this script relative to the extension dir.
    
var $extKey        'tt_news_change_image';    // The extension key.
    
var $pi_checkCHash true;
    var 
$cObj// The backReference to the mother cObj object set at call time
    
    /**
     * 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->cObj=t3lib_div::makeInstance('tslib_cObj');
        
$this->conf $conf;
      
$this->pi_loadLL(); // Loading language-labels
      
$this->pi_setPiVarDefaults(); // Set default piVars from TS
      
$this->pi_initPIflexForm(); // Init FlexForm configuration for plugin

        
$tt_news = new tx_ttnews;
        
$tx_news->cObj t3lib_div::makeInstance('tslib_cObj');        
        
$tt_news->enableFields $tx_news->cObj->enableFields('tt_news');
      
// initialize category vars
        
$tt_news->initCategoryVars();    <-эта строка вызывает ошибку
    
        $content
='';
        
        return 
$this->pi_wrapInBaseClass($content);
    }

}



if (
defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/tt_news_change_image/pi1/class.tx_ttnewschangeimage_pi1.php'])    {
    include_once(
$TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/tt_news_change_image/pi1/class.tx_ttnewschangeimage_pi1.php']);
}

?>

это вызывает ошибку:

Код HTML:

Fatal error: Call to a member function enableFields() on a non-object in /usr/local/apache2/htdocs/..мой сайт../typo3conf/ext/tt_news/pi/class.tx_ttnews.php on line 2730
Вызвано это тем что в class.tx_ttnews.php данная функция enableFields вызывается таким образом:
PHP код:

код расширения tt_news
$this
->enableCatFields $this->cObj->enableFields('tt_news_cat'); 

Получается что родительский объект cObj не инициализируется, хотя я явно задал его?

Я слабо разбираюсь в особенностях объектного программирования в php.

reva2 17.05.2011 02:02

Первое что бросилось в глаза:
Цитата:

$tt_news = new tx_ttnews;
а должно быть
Цитата:

$tt_news = new tx_ttnews();

shuman 17.05.2011 06:52

Сделал. Ошибка та же.

Пример взят из файла fe_index.php который был в версии tt_news 3.0

http://typo3.org/extensions/reposito...ash=e539286dac

Придется без подкатегорий писать расширение. Неохота кучу функций копировать из class.tx_tt_news.php

shuman 17.05.2011 07:33

нашел решение в news_calendar http://typo3.org/extensions/reposito...endar_pi1.php/

там это сделано так:
PHP код:

         if ( $this->categorySelection && $this->useSubCategories ) {
                
$this->categorySelection .= ',' tx_ttnews_div::getSubCategories$this->categorySelection );
            } 

видимо считается что объект tx_ttnews_div уже существует

shuman 17.05.2011 09:38

Виноват - версия tt_news 3.0.1 и есть последняя версия несмотря на 2009 год.

А у меня была старая - 2.5

В ней не было этой функции

dmartynenko 22.05.2011 17:03

На всякий случай - проблема с cObj решается просто, у вас в коде опечатка - вместо $tt_news указано $tx_news.

Также можно использовать $tt_news->cObj = $this->CObj;

shuman 23.05.2011 04:52

Цитата:

Сообщение от dmartynenko (Сообщение 31197)
На всякий случай - проблема с cObj решается просто, у вас в коде опечатка - вместо $tt_news указано $tx_news.

Также можно использовать $tt_news->cObj = $this->CObj;

Спасибо!


Часовой пояс GMT +4, время: 11:04.

Работает на vBulletin® версия 3.8.1.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Перевод: zCarot