PHP code example of maikschneider / category-tree

1. Go to this page and download the library: Download maikschneider/category-tree library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maikschneider / category-tree example snippets


return [
    'myext_reports' => [
        'parent' => 'web',
        'access' => 'user',
        'labels' => 'LLL:EXT:my_ext/Resources/Private/Language/locallang_mod.xlf',
        // Required: the parent module ships the page tree, and submodules inherit it
        // unless inheritance is switched off. Without this you get the page tree.
        'inheritNavigationComponentFromMainModule' => false,
        'navigationComponent' => '@maikschneider/category-tree/category-tree-element',
        'routes' => [
            '_default' => [
                'target' => \Vendor\MyExt\Controller\ReportController::class . '::handleRequest',
            ],
        ],
    ],
];

public function handleRequest(ServerRequestInterface $request): ResponseInterface
{
    $categoryUid = (int)($request->getQueryParams()['category'] ?? 0);
    // 0 means "no category selected" — the tree's root node clears the parameter.
}

$categoryUid = (int)($this->request->getQueryParams()['category'] ?? 0);

$subQuery = $connectionPool->getQueryBuilderForTable('sys_category_record_mm');
$recordUids = $subQuery
    ->select('uid_foreign')
    ->from('sys_category_record_mm')
    ->where(
        $subQuery->expr()->eq('uid_local', $subQuery->createNamedParameter($categoryUid, Connection::PARAM_INT)),
        $subQuery->expr()->eq('tablenames', $subQuery->createNamedParameter('tx_myext_domain_model_report')),
        $subQuery->expr()->eq('fieldname', $subQuery->createNamedParameter('categories')),
    )
    ->executeQuery()
    ->fetchFirstColumn();