typo3

TYPO3 Caching and the cHash

cHash?

There is a pretty old but nice article from Kasper, that explains the purpose of cHash[1].

To summarize this: If a cHash (or cache Hash) is part of the current URL, and if that cHash is correct, TYPO3 generates a cache entry for the generated content. The cHash is only correct if TYPO3 itself generated the URL.

So with the help of the cHash TYPO3 can cache multiple variants of a page – depending on its request parameters. This is used for example to cache all the detail views of your news records. (continue reading…)


Extbase – how to call controller action via Typoscript directly

If you have an extbase extension and you need to call a controller action via TypoScript, things have changed from TYPO3 4.7 to 6.1. TYPO3 6 has a lot of code rewritten, depends heavily on PHP namespaces and extbase extensions from earlier versions will no longer work.
To get started with all the necessary bootstrap code for a new extension, use the extension “extension_builder” from TER.

Let’s assume we have a little extension and we want to assign the result of a direct call of a controller action to a TS object.
Our controller code looks like this:

namespace MyVendorName\MyExtName\Controller;
class MyModelController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

public function myTestAction() {
return “some string”;
}

Please notice the namespace, this is very important! Your ext_localconf.php should look something like this:


\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
‘MyVendorName.’ . $_EXTKEY,
‘Pi1’,
array(
‘MyModel’ => ‘myTest’,
),
// non-cacheable actions
array(

)
);

‘Pi1’ is simply the name of the frontend plugin

TypoScript config

Now we set up a TS-object which should hold the output of our “myTestAction” method.

lib.myObj = USER
lib.myObj = 10
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
pluginName = Pi1
extensionName = MyExtName
controller = MyModel
vendorName = MyVendorName
action = myTest
switchableControllerActions {
MyModel {
1 = myTest
}
}

settings =< plugin.tx_myextname.settings persistence =< plugin.tx_myextname.persistence view =< plugin.tx_myextname.view update =< plugin.tx_myextname.update } The parameter “vendorName” is new and very important – it won’t work without it. Take care of the camel case notation too – the whole extbase framework is based on this case-sensitive coding convention. Now we are done – our controller action is directly called via TypoScript.


extbase update TS Setup

//site domain
        $baseURL = '';
        $templateData = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'sys_template', 'uid=1');
        $templateService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
        $templateService->ext_regObjectPositions($templateData['constants']);
        if(GeneralUtility::_GP('domain')){
            $urlInfo = parse_url(GeneralUtility::_GP('domain'));
            if(!isset($urlInfo['scheme'])){
                $baseURL = 'http://'.$urlInfo['path'].'/';
            }else{
                $baseURL = $urlInfo['scheme'].'://'.$urlInfo['host'].'/';
            }
        }
        $templateService->ext_putValueInConf('config.baseURL', $baseURL);
        // Set the data to be saved
        $recData = array();
        $recData['sys_template'][1]['constants'] = implode($templateService->raw, LF);
        // Create new  tce-object
        $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
        $tce->stripslashes_values = FALSE;
        $tce->start($recData, array());
        $tce->process_datamap();
        // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
        $tce->clear_cacheCmd('all');

TS Data

getText ist wohl die mächtigste Funktion, um mal eben von wo auch immer ein paar Daten herzuzaubern. Im Content-Objekt selbst heißt die Funktion getData. Schaut selbst welche Möglichkeiten angeboten werden.

Die Eigenschaft getText besteht aus mehreren Parametern. Der erste Parameter wird mit einem Doppelpunkt von allen anderen Parametern getrennt. Alle weiteren Parameter werden mit Hilfe der | Pipe unterteilt. (continue reading…)


TS lightbox 配置

config {
  disableAllHeaderCode = 1
  #additionalHeaders = Content-type:application/json
  xhtml_cleaning = 0
  admPanel = 0
  debug = 0
  no_cache = 1
}
page.includeJS>
page.includeCSS>
page.includeJSFooterlibs>

TS取FAL Files

TS取FAL Files

        40 =  FILES
        40 {
          references {
            table = tt_content
            #uid.data = uid
            fieldName = image
          }
          #renderObj = TEXT
          #renderObj {
          #  data = file:current:publicUrl
          #  wrap = 
#} renderObj = IMAGE renderObj { file.import.data = file:current:publicUrl file.height = 103 wrap = |
stdWrap.typolink.parameter.data = field:header_link } }

TYPO3 Ajax Page Configuration

ajax = PAGE
ajax {
  typeNum = 1234

  10 < plugin.myextension_pi1     

  config {
    disableAllHeaderCode = 1
    additionalHeaders = Content-type:application/json
    xhtml_cleaning = 0
    admPanel = 0
    debug = 0
    no_cache = 1
  }
}

Typo3 Inline Localiztion

'description' => array(
			'exclude' => 1,
			'label' => 'LLL:EXT:ext_product/Resources/Private/Language/locallang_db.xlf:tx_extproduct_domain_model_product.description',
			'config' => array(
				'type' => 'inline',
				'foreign_table' => 'tt_content',
				'minitems' => 0,
				'maxitems' => 999,
                'appearance' => array(
                    'collapseAll' => 1,
                    'expandSingle' => 1,
                    'levelLinksPosition' => 'bottom',
                    'useSortable' => 1,
                    'showPossibleLocalizationRecords' => 1,
                    'showRemovedLocalizationRecords' => 1,
                    'showAllLocalizationLink' => 1,
                    //'showSynchronizationLink' => 1,
                    'enabledControls' => array(
                        'info' => FALSE,
                    )
                )
			)
		),

Get File Relation

//Here is a small snippet I use to get uploaded images from a content object (tt_content).

public function getContentImages($tt_content_uid) {
    /** @var \TYPO3\CMS\Core\Resource\FileRepository $fileRepository */
    $fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\FileRepository');
    $fileObjects = $fileRepository->findByRelation('tt_content', 'image', $tt_content_uid);

    // Get file information
    $files = array();
    foreach ($fileObjects as $key => $value) {
        $file = array();
        $file['reference'] = $value->getReferenceProperties();
        $file['original'] = $value->getOriginalFile()->getProperties();
        $files[] = $file;
    }

    return $files;
}

How I can render Content Object from tt_content

In Extbase extensions $this->cObj is no more available in the current scope, so you need to get it firts before you can use:
In controller

/**
     * @param $pageUid
     * @param int $colPos
     * @return string
     */
    private function getTTContent($pageUid, $colPos = 0)
    {
        $contentObj = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
        $conf['table'] = 'tt_content';
        $conf['select.'] = array(
            'pidInList' => $pageUid,
            'where' => 'colPos=' . $colPos
        );
        return $contentObj->cObjGetSingle('CONTENT', $conf);
        /*$tt_contents = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'tt_content', 'deleted=0 and hidden=0 and pid=' . $pageUid . ' and colPos=' . $colPos . ' and sys_language_uid=' . $GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid'], '', 'sorting asc');
        if (!empty($tt_contents)) {
            $contentObj = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
            foreach ($tt_contents as $tt_content) {
                $conf['tables'] = 'tt_content';
                $conf['source'] = $tt_content['uid'];
                $tempContent .= $contentObj->cObjGetSingle('RECORDS', $conf);
            }
        }
        return $tempContent;*/
    }

 

$cObj = $this->configurationManager->getContentObject();
$ttContentConfig = array(
    'tables'       => 'tt_content',
    'source'       => 123,
    'dontCheckPid' => 1
);
$content .= $cObj->RECORDS($ttContentConfig);

In model.

/*
	 * get TT content
	 */
	public function getTTcontent($uids){
		$content = '';
		$tempArray = explode(",", $uids);
		$cObj = $GLOBALS['TSFE']->cObj;
		foreach($tempArray as $uid){
			$ttContentConfig = array(
				'tables'       => 'tt_content',
				'source'       => $uid,
				'dontCheckPid' => 1
			);
			$content .= $cObj->RECORDS($ttContentConfig);
		}
		return $content;
	}

lib.footer.social = RECORDS
lib.footer.social {
    source = 140
    dontCheckPid = 1
    tables = tt_content
}

 


Copyright © 1996-2010 Add Lives. All rights reserved.
iDream theme by Templates Next | Powered by WordPress