最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - TYPO3 12 Backend Module – How to store a checkbox value and use it in the frontend? - Stack Overflow

programmeradmin0浏览0评论

I'm currently developing a custom backend module in TYPO3 12 and want to store a checkbox value so that I can retrieve it in the frontend (Fluid template).

I successfully created the backend module using this video: ▶

However, the video (and all other resources I found) do not explain how to store form inputs and retrieve them later.

My current setup:

BackendController.php


<?php

namespace LjBarrierefrei\Controller;

use TYPO3\CMS\Backend\Attribute\AsController;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use Psr\Http\Message\ResponseInterface;

#[AsController]
final class BackendController extends ActionController
{
    public function __construct(
        protected readonly ModuleTemplateFactory $moduleTemplateFactory,
    ) {
    }
    public function indexAction(): ResponseInterface
    {
        $this->view->assign('someVar', 'someContent');
        $moduleTemplate = $this->moduleTemplateFactory->create($this->request);

        $moduleTemplate->setContent($this->view->render());
        return $this->htmlResponse($moduleTemplate->renderContent());

    }
}

Fluid Template Index.html (Backend module UI)



<div class="m-lg-5 border p-4">
<h1>Barrierefrei Einstellungen</h1>
    <p>Hier können Sie die Moduleinstellungen konfigurieren.!!!!</p>
    <f:form action="save">
        <label>
            <f:form.checkbox name="enable_barrierefrei" value="1" checked="{enableBarrierefrei}" />
            Barrierefreiheit aktivieren
        </label>
        <f:form.submit value="Speichern" />
    </f:form>

</div>

My question:

How can I properly store the checkbox value so that: The setting is persisted after saving I can retrieve the value in the frontend (e.g., in Fluid {settings.enableBarrierFree})

I am unsure about the best way to store the checkbox value:

Should I store it in a TYPO3 database table?

Can I store it using TYPO3 configuration ($GLOBALS['TYPO3_CONF_VARS'])?

What is the best practice in TYPO3 12 backend modules for storing such settings?

If anyone has a clear explanation or example, I would really appreciate your help!

发布评论

评论列表(0)

  1. 暂无评论